Change in openvpn[master]: Bind to multiple ipv4/ipv6 addresses
A message that is not in the archive (sent off-list or not yet received): gerrit.1727098847000.I31bbf87e4e568021445c7512ecefadfd4a69b363@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to review the following change.
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Bind to multiple ipv4/ipv6 addresses
Enables the binding of multiple listen
sockets based on the specified "--local"
directives.
The main server loop has been updated
to handle both TCP and UDP connections.
The hash function has also been modified
to include the protocol during the
creation of new client instances.
---
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mroute.c
M src/openvpn/mroute.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
14 files changed, 419 insertions(+), 278 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/1
src/openvpn/forward.c +171 -3
@@ -1764,7 +1764,7 @@if (c->options.shaper) {int overhead =datagram_overhead (c->c2.to_link_addr->dest.addr.sa.sa_family, - c->options.ce.proto); + ls->info.proto);shaper_wrote_bytes (&c->c2.shaper,BLEN (&c->c2.to_link) + overhead); }
@@ -1805,8 +1805,8 @@/* Send packet */ size = (int )link_socket_write (ls, - &c->c2.to_link, - to_addr); + &c->c2.to_link, + to_addr);/* Undo effect of prepend */ link_socket_write_post_size_adjust (&size, size_delta, &c->c2.to_link);
@@ -2054,6 +2054,173 @@*/ void +get_io_flags_dowork_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags) +{ +unsigned int socket =0 ; +unsigned int tuntap =0 ; +static uintptr_t tun_shift =2 ; +static uintptr_t err_shift =4 ; + +/* +* Calculate the flags based on the provided 'flags' argument. +*/ +if (flags &IOW_WAIT_SIGNAL ) + { +wait_signal (multi_io->es, (void *)err_shift); + } + +if (flags &IOW_TO_LINK ) + { +if (flags &IOW_SHAPER ) + { +/* +* If sending this packet would put us over our traffic shaping +* quota, don't send -- instead compute the delay we must wait +* until it will be OK to send the packet. +*/ +int delay =0 ; + +/* set traffic shaping delay in microseconds */ +if (c->options.shaper) + { + delay =max_int (delay,shaper_delay (&c->c2.shaper)); + } + +if (delay <1000 ) + { + socket |=EVENT_WRITE ; + } +else + { +shaper_soonest_event (&c->c2.timeval, delay); + } + } +else + { + socket |=EVENT_WRITE ; + } + } +else if (!((flags &IOW_FRAG ) &&TO_LINK_FRAG (c))) + { +if (flags &IOW_READ_TUN ) + { + tuntap |=EVENT_READ ; + } + } + +/* +* If outgoing data (for TUN/TAP device) pending, wait for ready-to-send status +* from device. Otherwise, wait for incoming data on TCP/UDP port. +*/ +if (flags &IOW_TO_TUN ) + { + tuntap |=EVENT_WRITE ; + } +else + { +if (flags &IOW_READ_LINK ) + { + socket |=EVENT_READ ; + } + } + +/* +* outgoing bcast buffer waiting to be sent? +*/ +if (flags &IOW_MBUF ) + { + socket |=EVENT_WRITE ; + } + +/* +* Force wait on TUN input, even if also waiting on TCP/UDP output +*/ +if (flags &IOW_READ_TUN_FORCE ) + { + tuntap |=EVENT_READ ; + } + +#ifdef _WIN32 +if (tuntap_is_wintun (c->c1.tuntap)) + { +/* +* With wintun we are only interested in read event. Ring buffer is +* always ready for write, so we don't do wait. +*/ + tuntap =EVENT_READ ; + } +#endif + +/* +* Configure event wait based on socket, tuntap flags. +*/ +for (int i =0 ; i < c->c1.link_sockets_num; i++) + { +if (proto_is_dgram (c->c2.link_sockets[i]->info.proto)) + { +socket_set (c->c2.link_sockets[i], multi_io->es, socket, + &c->c2.link_sockets[i]->ev_arg,NULL ); + } + } +tun_set (c->c1.tuntap, multi_io->es, tuntap, (void *)tun_shift,NULL ); + + multi_io->udp_flags = socket | tuntap; +} + +void +get_io_flags_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags) +{ + multi_io->udp_flags =ES_ERROR ; +if (c->c2.fast_io && (flags & (IOW_TO_TUN |IOW_TO_LINK |IOW_MBUF ))) + { +/* fast path -- only for TUN/TAP/UDP writes */ +unsigned int ret =0 ; +if (flags &IOW_TO_TUN ) + { + ret |=TUN_WRITE ; + } +if (flags & (IOW_TO_LINK |IOW_MBUF )) + { + ret |=SOCKET_WRITE ; + } + multi_io->udp_flags = ret; + } +else + { +#ifdef _WIN32 +bool skip_iowait = flags &IOW_TO_TUN ; +if (flags &IOW_READ_TUN ) + { +/* +* don't read from tun if we have pending write to link, +* since every tun read overwrites to_link buffer filled +* by previous tun read +*/ + skip_iowait = !(flags &IOW_TO_LINK ); + } +if (tuntap_is_wintun (c->c1.tuntap) && skip_iowait) + { +unsigned int ret =0 ; +if (flags &IOW_TO_TUN ) + { + ret |=TUN_WRITE ; + } +if (flags &IOW_READ_TUN ) + { + ret |=TUN_READ ; + } + multi_io->udp_flags = ret; + } + else +#endif /* ifdef _WIN32 */ + { +/* slow path - delegate to io_wait_dowork_udp to calculate flags */ +get_io_flags_dowork_udp (c, multi_io, flags); + } + } +} + +void io_wait_dowork (struct context *c,const unsigned int flags) {unsigned int socket =0 ;
@@ -2295,6 +2462,7 @@dmsg (D_EVENT_WAIT ,"I/O WAIT status=0x%04x" , c->c2.event_set_status); } +void process_io (struct context *c,struct link_socket *ls) {
src/openvpn/forward.h +4 -0
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
src/openvpn/init.c +41 -17
107 lines not on this page · raw message
src/openvpn/mroute.c +1 -0
@@ -421,6 +421,7 @@ {buf_printf (&out,":%d" ,ntohs (maddr.v4.port)); } +buf_printf (&out,":%d" , maddr.proto); }break ;
src/openvpn/mroute.h +6 -1
@@ -76,6 +76,7 @@uint8_t len;/* length of address */ uint8_t unused;uint8_t type;/* MR_ADDR/MR_WITH flags */ +uint8_t proto;uint8_t netbits;/* number of bits in network part of address, * valid if MR_WITH_NETBITS is set */ union {
@@ -201,6 +202,10 @@ {return false; } +if (a1->proto != a2->proto) + { +return false; + }if (a1->netbits != a2->netbits) {return false;
@@ -222,7 +227,7 @@static inline uint32_t mroute_addr_hash_len (const struct mroute_addr *a) { -return (uint32_t ) a->len +2 ; +return (uint32_t ) a->len +3 ; } static inline void
src/openvpn/mtcp.c +1 -85
95 lines not on this page · raw message
src/openvpn/mtcp.h +0 -11
@@ -51,17 +51,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_protocol *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +52 -123
199 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +101 -16
159 lines not on this page · raw message
src/openvpn/multi.h +7 -6
@@ -247,10 +247,8 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() +* This function calls the main event loop function +* on the transport protocols: * * @param top - Top-level context structure. */
@@ -263,7 +261,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
@@ -659,9 +657,12 @@ multi_process_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags) { struct multi_instance *mi = m->pending; +if (!mi) + { +return false; + }bool ret = true; -ASSERT (mi); #ifdef MULTI_DEBUG_EVENT_LOOP printf("%s -> TUN len=%d\n", id(mi),
src/openvpn/openvpn.h +2 -2
@@ -220,8 +220,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point(), \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +30 -3
@@ -2199,6 +2199,7 @@ } ALLOC_OBJ_CLEAR_GC(e, struct local_entry, gc); + e->proto =PROTO_NONE ; l->array[l->len++] = e;return e;
@@ -3170,14 +3171,30 @@if (ce->proto ==PROTO_TCP ) { ce->proto =PROTO_TCP_SERVER ; + o->ce.proto = ce->proto; + } +if (ce->local_list) + { +for (int i =0 ; i < ce->local_list->len; i++) + { +if (ce->local_list->array[i]->proto ==PROTO_TCP ) + { + ce->local_list->array[i]->proto =PROTO_TCP_SERVER ; + } +else if (ce->local_list->array[i]->proto ==PROTO_NONE ) + { + ce->local_list->array[i]->proto = ce->proto; + } + } } } -if (o->client) +if (o->mode !=MODE_SERVER ) {if (ce->proto ==PROTO_TCP ) { ce->proto =PROTO_TCP_CLIENT ; + o->ce.proto = ce->proto; } }
@@ -3331,6 +3348,10 @@ { le->port = o->ce.local_port; } +if (!le->proto) + { + le->proto = o->ce.proto; + } }#ifdef _WIN32
@@ -3822,6 +3843,7 @@ASSERT (e); e->port = o->ce.local_port; e->bind_local = o->ce.bind_local; + e->proto = o->ce.proto; }/* use the same listen list for every outgoing connection */
@@ -6232,7 +6254,7 @@VERIFY_PERMISSION (OPT_P_UP ); options->ifconfig_nowarn = true; } -else if (streq (p[0 ],"local" ) && p[1 ] && !p[3 ]) +else if (streq (p[0 ],"local" ) && p[1 ] && !p[4 ]) {struct local_entry *e;
@@ -6253,7 +6275,12 @@if (p[2 ]) { e->port = p[2 ]; - e->bind_local = true; +/*e->bind_local = true; */ + } + +if (p[3 ]) + { + e->proto =ascii2proto (p[3 ]); } }else if (streq (p[0 ],"remote-random" ) && !p[1 ])
src/openvpn/options.h +1 -0
@@ -99,6 +99,7 @@const char *local;const char *port;bool bind_local; +int proto; };struct connection_entry
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to look at the new patch set (#2).
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Bind to multiple ipv4/ipv6 addresses
Enables the binding of multiple listen
sockets based on the specified "--local"
directives.
The main server loop has been updated
to handle both TCP and UDP connections.
The hash function has also been modified
to include the protocol during the
creation of new client instances.
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mroute.c
M src/openvpn/mroute.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
15 files changed, 418 insertions(+), 277 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/2
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +169 -1
188 lines not on this page · raw message
src/openvpn/forward.h +4 -0
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
src/openvpn/init.c +41 -17
107 lines not on this page · raw message
src/openvpn/mroute.c +1 -0
@@ -421,6 +421,7 @@ {buf_printf (&out,":%d" ,ntohs (maddr.v4.port)); } +buf_printf (&out,":%d" , maddr.proto); }break ;
src/openvpn/mroute.h +6 -1
@@ -76,6 +76,7 @@uint8_t len;/* length of address */ uint8_t unused;uint8_t type;/* MR_ADDR/MR_WITH flags */ +uint8_t proto;uint8_t netbits;/* number of bits in network part of address, * valid if MR_WITH_NETBITS is set */ union {
@@ -201,6 +202,10 @@ {return false; } +if (a1->proto != a2->proto) + { +return false; + }if (a1->netbits != a2->netbits) {return false;
@@ -222,7 +227,7 @@static inline uint32_t mroute_addr_hash_len (const struct mroute_addr *a) { -return (uint32_t ) a->len +2 ; +return (uint32_t ) a->len +3 ; } static inline void
src/openvpn/mtcp.c +1 -85
95 lines not on this page · raw message
src/openvpn/mtcp.h +0 -11
@@ -51,17 +51,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_protocol *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +52 -123
199 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +101 -16
159 lines not on this page · raw message
src/openvpn/multi.h +7 -6
@@ -252,10 +252,8 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() +* This function calls the main event loop function +* on the transport protocols: * * @param top - Top-level context structure. */
@@ -268,7 +266,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
@@ -664,9 +662,12 @@ multi_process_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags) { struct multi_instance *mi = m->pending; +if (!mi) + { +return false; + }bool ret = true; -ASSERT (mi); #ifdef MULTI_DEBUG_EVENT_LOOP printf("%s -> TUN len=%d\n", id(mi),
src/openvpn/openvpn.h +2 -2
@@ -220,8 +220,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point(), \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +30 -3
@@ -2199,6 +2199,7 @@ } ALLOC_OBJ_CLEAR_GC(e, struct local_entry, gc); + e->proto =PROTO_NONE ; l->array[l->len++] = e;return e;
@@ -3170,14 +3171,30 @@if (ce->proto ==PROTO_TCP ) { ce->proto =PROTO_TCP_SERVER ; + o->ce.proto = ce->proto; + } +if (ce->local_list) + { +for (int i =0 ; i < ce->local_list->len; i++) + { +if (ce->local_list->array[i]->proto ==PROTO_TCP ) + { + ce->local_list->array[i]->proto =PROTO_TCP_SERVER ; + } +else if (ce->local_list->array[i]->proto ==PROTO_NONE ) + { + ce->local_list->array[i]->proto = ce->proto; + } + } } } -if (o->client) +if (o->mode !=MODE_SERVER ) {if (ce->proto ==PROTO_TCP ) { ce->proto =PROTO_TCP_CLIENT ; + o->ce.proto = ce->proto; } }
@@ -3331,6 +3348,10 @@ { le->port = o->ce.local_port; } +if (!le->proto) + { + le->proto = o->ce.proto; + } }#ifdef _WIN32
@@ -3822,6 +3843,7 @@ASSERT (e); e->port = o->ce.local_port; e->bind_local = o->connection_list->array[0 ]->bind_local; + e->proto = o->ce.proto; }/* use the same listen list for every outgoing connection */
@@ -6232,7 +6254,7 @@VERIFY_PERMISSION (OPT_P_UP ); options->ifconfig_nowarn = true; } -else if (streq (p[0 ],"local" ) && p[1 ] && !p[3 ]) +else if (streq (p[0 ],"local" ) && p[1 ] && !p[4 ]) {struct local_entry *e;
@@ -6253,7 +6275,12 @@if (p[2 ]) { e->port = p[2 ]; - e->bind_local = true; +/*e->bind_local = true; */ + } + +if (p[3 ]) + { + e->proto =ascii2proto (p[3 ]); } }else if (streq (p[0 ],"remote-random" ) && !p[1 ])
src/openvpn/options.h +1 -0
@@ -99,6 +99,7 @@const char *local;const char *port;bool bind_local; +int proto; };struct connection_entry
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Patch Set 2: Code-Review-2
(1 comment)
Patchset:
PS2:
Break t_server_null
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Wed, 02 Oct 2024 10:25:13 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to look at the new patch set (#3).
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Bind to multiple ipv4/ipv6 addresses
Enables the binding of multiple listen sockets based on the specified "--local" directives.
The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances.
There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mroute.c
M src/openvpn/mroute.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
16 files changed, 548 insertions(+), 320 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/3
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +169 -1
188 lines not on this page · raw message
src/openvpn/forward.h +4 -0
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
src/openvpn/init.c +80 -41
234 lines not on this page · raw message
src/openvpn/mroute.c +1 -0
@@ -421,6 +421,7 @@ {buf_printf (&out,":%d" ,ntohs (maddr.v4.port)); } +buf_printf (&out,":%d" , maddr.proto); }break ;
src/openvpn/mroute.h +5 -1
@@ -201,6 +201,10 @@ {return false; } +if (a1->proto != a2->proto) + { +return false; + }if (a1->netbits != a2->netbits) {return false;
@@ -222,7 +226,7 @@static inline uint32_t mroute_addr_hash_len (const struct mroute_addr *a) { -return (uint32_t ) a->len +2 ; +return (uint32_t ) a->len +3 ; } static inline void
src/openvpn/mtcp.c +14 -91
120 lines not on this page · raw message
src/openvpn/mtcp.h +0 -11
@@ -51,17 +51,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_protocol *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +45 -123
192 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +112 -24
203 lines not on this page · raw message
src/openvpn/multi.h +8 -6
@@ -205,6 +205,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -252,10 +253,8 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() +* This function calls the main event loop function +* on the transport protocols: * * @param top - Top-level context structure. */
@@ -268,7 +267,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
@@ -664,9 +663,12 @@ multi_process_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags) { struct multi_instance *mi = m->pending; +if (!mi) + { +return false; + }bool ret = true; -ASSERT (mi); #ifdef MULTI_DEBUG_EVENT_LOOP printf("%s -> TUN len=%d\n", id(mi),
src/openvpn/multi_io.c +42 -0
60 lines not on this page · raw message
src/openvpn/openvpn.h +2 -2
@@ -220,8 +220,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point(), \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +60 -8
132 lines not on this page · raw message
src/openvpn/options.h +3 -0
@@ -99,6 +99,7 @@const char *local;const char *port;bool bind_local; +int proto; };struct connection_entry
@@ -916,6 +917,8 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to look at the new patch set (#4).
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Bind to multiple ipv4/ipv6 addresses
Enables the binding of multiple listen sockets based on the specified "--local" directives.
The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances.
There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mroute.c
M src/openvpn/mroute.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
16 files changed, 548 insertions(+), 320 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/4
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +169 -1
188 lines not on this page · raw message
src/openvpn/forward.h +4 -0
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
src/openvpn/init.c +80 -41
234 lines not on this page · raw message
src/openvpn/mroute.c +1 -0
@@ -421,6 +421,7 @@ {buf_printf (&out,":%d" ,ntohs (maddr.v4.port)); } +buf_printf (&out,":%d" , maddr.proto); }break ;
src/openvpn/mroute.h +5 -1
@@ -201,6 +201,10 @@ {return false; } +if (a1->proto != a2->proto) + { +return false; + }if (a1->netbits != a2->netbits) {return false;
@@ -222,7 +226,7 @@static inline uint32_t mroute_addr_hash_len (const struct mroute_addr *a) { -return (uint32_t ) a->len +2 ; +return (uint32_t ) a->len +3 ; } static inline void
src/openvpn/mtcp.c +14 -91
120 lines not on this page · raw message
src/openvpn/mtcp.h +0 -11
@@ -51,17 +51,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_protocol *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +45 -123
192 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +112 -24
203 lines not on this page · raw message
src/openvpn/multi.h +8 -6
@@ -205,6 +205,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -252,10 +253,8 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() +* This function calls the main event loop function +* on the transport protocols: * * @param top - Top-level context structure. */
@@ -268,7 +267,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
@@ -664,9 +663,12 @@ multi_process_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags) { struct multi_instance *mi = m->pending; +if (!mi) + { +return false; + }bool ret = true; -ASSERT (mi); #ifdef MULTI_DEBUG_EVENT_LOOP printf("%s -> TUN len=%d\n", id(mi),
src/openvpn/multi_io.c +42 -0
60 lines not on this page · raw message
src/openvpn/openvpn.h +2 -2
@@ -220,8 +220,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point(), \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +60 -8
132 lines not on this page · raw message
src/openvpn/options.h +3 -0
@@ -99,6 +99,7 @@const char *local;const char *port;bool bind_local; +int proto; };struct connection_entry
@@ -916,6 +917,8 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Patch Set 4: -Code-Review
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Thu, 17 Oct 2024 10:34:18 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to look at the new patch set (#5).
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Bind to multiple ipv4/ipv6 addresses
Enables the binding of multiple listen sockets based on the specified "--local" directives.
The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances.
There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mroute.c
M src/openvpn/mroute.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c
17 files changed, 539 insertions(+), 311 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/5
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +169 -1
188 lines not on this page · raw message
src/openvpn/forward.h +4 -0
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
src/openvpn/init.c +43 -28
165 lines not on this page · raw message
src/openvpn/mroute.c +1 -0
@@ -421,6 +421,7 @@ {buf_printf (&out,":%d" ,ntohs (maddr.v4.port)); } +buf_printf (&out,":%d" , maddr.proto); }break ;
src/openvpn/mroute.h +5 -1
@@ -201,6 +201,10 @@ {return false; } +if (a1->proto != a2->proto) + { +return false; + }if (a1->netbits != a2->netbits) {return false;
@@ -222,7 +226,7 @@static inline uint32_t mroute_addr_hash_len (const struct mroute_addr *a) { -return (uint32_t ) a->len +2 ; +return (uint32_t ) a->len +3 ; } static inline void
src/openvpn/mtcp.c +14 -91
120 lines not on this page · raw message
src/openvpn/mtcp.h +0 -11
@@ -51,17 +51,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_protocol *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +45 -123
192 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +113 -24
204 lines not on this page · raw message
src/openvpn/multi.h +8 -6
@@ -204,6 +204,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -251,10 +252,8 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() +* This function calls the main event loop function +* on the transport protocols: * * @param top - Top-level context structure. */
@@ -267,7 +266,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
@@ -663,9 +662,12 @@ multi_process_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags) { struct multi_instance *mi = m->pending; +if (!mi) + { +return false; + }bool ret = true; -ASSERT (mi); #ifdef MULTI_DEBUG_EVENT_LOOP printf("%s -> TUN len=%d\n", id(mi),
src/openvpn/multi_io.c +42 -0
60 lines not on this page · raw message
src/openvpn/openvpn.h +2 -2
@@ -220,8 +220,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point(), \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +60 -8
132 lines not on this page · raw message
src/openvpn/options.h +3 -0
@@ -99,6 +99,7 @@const char *local;const char *port;bool bind_local; +int proto; };struct connection_entry
@@ -916,6 +917,8 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
src/openvpn/socket.c +27 -4
@@ -1874,16 +1874,39 @@ int sock_index, int mode) { +const char *host = c->options.ce.local_list->array[sock_index]->local; +const char *port = c->options.ce.local_list->array[sock_index]->port; +int proto = c->options.ce.local_list->array[sock_index]->proto; +bool bind_local = c->options.ce.local_list->array[sock_index]->bind_local; + +if (c->mode ==CM_CHILD_TCP || c->mode ==CM_CHILD_UDP ) + { +struct link_socket *tmp_sock =NULL ; +if (c->mode ==CM_CHILD_TCP ) + { + tmp_sock = (struct link_socket *)c->c2.accept_from; + } +else if (c->mode ==CM_CHILD_UDP ) + { + tmp_sock = c->c2.link_sockets[0 ]; + } + + host = tmp_sock->local_host; + port = tmp_sock->local_port; + proto = tmp_sock->info.proto; + bind_local = tmp_sock->bind_local; + } +ASSERT (c->c2.link_sockets[sock_index]); - c->c2.link_sockets[sock_index]->local_host = c->options.ce.local_list->array[sock_index]->local; - c->c2.link_sockets[sock_index]->local_port = c->options.ce.local_list->array[sock_index]->port; + c->c2.link_sockets[sock_index]->local_host = host; + c->c2.link_sockets[sock_index]->local_port = port; c->c2.link_sockets[sock_index]->remote_host = c->options.ce.remote; c->c2.link_sockets[sock_index]->remote_port = c->options.ce.remote_port; c->c2.link_sockets[sock_index]->dns_cache = c->c1.dns_cache; c->c2.link_sockets[sock_index]->http_proxy = c->c1.http_proxy; c->c2.link_sockets[sock_index]->socks_proxy = c->c1.socks_proxy; - c->c2.link_sockets[sock_index]->bind_local = c->options.ce.local_list->array[sock_index]->bind_local; + c->c2.link_sockets[sock_index]->bind_local = bind_local; c->c2.link_sockets[sock_index]->resolve_retry_seconds = c->options.resolve_retry_seconds; c->c2.link_sockets[sock_index]->mtu_discover_type = c->options.ce.mtu_discover_type;
@@ -1905,7 +1928,7 @@ c->c2.link_sockets[sock_index]->mark = c->options.mark; - c->c2.link_sockets[sock_index]->info.proto = c->options.ce.proto; + c->c2.link_sockets[sock_index]->info.proto = proto; c->c2.link_sockets[sock_index]->info.af = c->options.ce.af; c->c2.link_sockets[sock_index]->info.remote_float = c->options.ce.remote_float; c->c2.link_sockets[sock_index]->info.lsa = &c->c1.link_socket_addrs[sock_index];
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 5
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to look at the new patch set (#7).
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Bind to multiple ipv4/ipv6 addresses
Enables the binding of multiple listen sockets based on the specified "--local" directives.
The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances.
There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mroute.c
M src/openvpn/mroute.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c
17 files changed, 507 insertions(+), 316 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/7
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +169 -1
188 lines not on this page · raw message
src/openvpn/forward.h +4 -0
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
src/openvpn/init.c +43 -28
165 lines not on this page · raw message
src/openvpn/mroute.c +1 -0
@@ -421,6 +421,7 @@ {buf_printf (&out,":%d" ,ntohs (maddr.v4.port)); } +buf_printf (&out,":%d" , maddr.proto); }break ;
src/openvpn/mroute.h +5 -1
@@ -201,6 +201,10 @@ {return false; } +if (a1->proto != a2->proto) + { +return false; + }if (a1->netbits != a2->netbits) {return false;
@@ -222,7 +226,7 @@static inline uint32_t mroute_addr_hash_len (const struct mroute_addr *a) { -return (uint32_t ) a->len +2 ; +return (uint32_t ) a->len +3 ; } static inline void
src/openvpn/mtcp.c +14 -91
120 lines not on this page · raw message
src/openvpn/mtcp.h +0 -11
@@ -51,17 +51,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_protocol *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +45 -127
196 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m,struct link_socket *sock);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +112 -23
196 lines not on this page · raw message
src/openvpn/multi.h +8 -6
@@ -204,6 +204,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -251,10 +252,8 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() +* This function calls the main event loop function +* on the transport protocols: * * @param top - Top-level context structure. */
@@ -267,7 +266,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
@@ -663,9 +662,12 @@ multi_process_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags) { struct multi_instance *mi = m->pending; +if (!mi) + { +return false; + }bool ret = true; -ASSERT (mi); #ifdef MULTI_DEBUG_EVENT_LOOP printf("%s -> TUN len=%d\n", id(mi),
src/openvpn/multi_io.c +11 -2
@@ -142,6 +142,11 @@ &m->top.c2.link_sockets[i]->ev_arg); } +if (has_udp_in_local_list (&m->top.options)) + { +get_io_flags_udp (&m->top, m->multi_io,p2mp_iow_flags (m)); + } +#ifdef _WIN32if (tuntap_is_wintun (m->top.c1.tuntap)) {
@@ -429,14 +434,13 @@ }break ; -/* new incoming TCP client attempting to connect? */ case EVENT_ARG_LINK_SOCKET :if (!ev_arg->u.sock) {msg (D_MULTI_ERRORS ,"MULTI PROTOCOL: multi_proto_proc_io: null socket" );break ; } - +/* new incoming TCP client attempting to connect? */ if (!proto_is_dgram (ev_arg->u.sock->info.proto)) {socket_reset_listen_persistent (ev_arg->u.sock);
@@ -447,6 +451,11 @@ }break ; } +else + { +multi_process_io_udp (m, ev_arg->u.sock); +break ; + } } }else
src/openvpn/openvpn.h +2 -2
@@ -216,8 +216,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point(), \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +59 -7
130 lines not on this page · raw message
src/openvpn/options.h +3 -0
@@ -98,6 +98,7 @@ {const char *local;const char *port; +int proto; };struct connection_entry
@@ -915,6 +916,8 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
src/openvpn/socket.c +28 -5
@@ -1878,10 +1878,33 @@struct options *o = &c->options;ASSERT (sock); - sock->local_host = o->ce.local_list->array[sock_index]->local; - sock->local_port = o->ce.local_list->array[sock_index]->port; - sock->remote_host = o->ce.remote; - sock->remote_port = o->ce.remote_port; +const char *host = o->ce.local_list->array[sock_index]->local; +const char *port = o->ce.local_list->array[sock_index]->port; +int proto = o->ce.local_list->array[sock_index]->proto; + +if (c->mode ==CM_CHILD_TCP || c->mode ==CM_CHILD_UDP ) + { +struct link_socket *tmp_sock =NULL ; +if (c->mode ==CM_CHILD_TCP ) + { + tmp_sock = (struct link_socket *)c->c2.accept_from; + } +else if (c->mode ==CM_CHILD_UDP ) + { + tmp_sock = c->c2.link_sockets[0 ]; + } + + host = tmp_sock->local_host; + port = tmp_sock->local_port; + proto = tmp_sock->info.proto; + } + +ASSERT (c->c2.link_sockets[sock_index]); + + sock->local_host = host; + sock->local_port = port; + sock->remote_host = c->options.ce.remote; + sock->remote_port = c->options.ce.remote_port; sock->dns_cache = c->c1.dns_cache; sock->http_proxy = c->c1.http_proxy; sock->socks_proxy = c->c1.socks_proxy;
@@ -1907,7 +1930,7 @@ sock->mark = o->mark; - sock->info.proto = o->ce.proto; + sock->info.proto = proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; sock->info.lsa = &c->c1.link_socket_addrs[sock_index];
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 7
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to look at the new patch set (#10).
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Bind to multiple ipv4/ipv6 addresses
Enables the binding of multiple listen sockets based on the specified "--local" directives.
The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances.
There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mroute.c
M src/openvpn/mroute.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c
17 files changed, 504 insertions(+), 314 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/10
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +169 -1
188 lines not on this page · raw message
src/openvpn/forward.h +4 -0
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
src/openvpn/init.c +43 -28
165 lines not on this page · raw message
src/openvpn/mroute.c +1 -0
@@ -421,6 +421,7 @@ {buf_printf (&out,":%d" ,ntohs (maddr.v4.port)); } +buf_printf (&out,":%d" , maddr.proto); }break ;
src/openvpn/mroute.h +5 -1
@@ -201,6 +201,10 @@ {return false; } +if (a1->proto != a2->proto) + { +return false; + }if (a1->netbits != a2->netbits) {return false;
@@ -222,7 +226,7 @@static inline uint32_t mroute_addr_hash_len (const struct mroute_addr *a) { -return (uint32_t ) a->len +2 ; +return (uint32_t ) a->len +3 ; } static inline void
src/openvpn/mtcp.c +14 -91
120 lines not on this page · raw message
src/openvpn/mtcp.h +0 -11
@@ -51,17 +51,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_protocol *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +45 -127
196 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m,struct link_socket *sock);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +112 -23
196 lines not on this page · raw message
src/openvpn/multi.h +8 -6
@@ -205,6 +205,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -252,10 +253,8 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() +* This function calls the main event loop function +* on the transport protocols: * * @param top - Top-level context structure. */
@@ -268,7 +267,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
@@ -664,9 +663,12 @@ multi_process_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags) { struct multi_instance *mi = m->pending; +if (!mi) + { +return false; + }bool ret = true; -ASSERT (mi); #ifdef MULTI_DEBUG_EVENT_LOOP printf("%s -> TUN len=%d\n", id(mi),
src/openvpn/multi_io.c +11 -2
@@ -142,6 +142,11 @@ &m->top.c2.link_sockets[i]->ev_arg); } +if (has_udp_in_local_list (&m->top.options)) + { +get_io_flags_udp (&m->top, m->multi_io,p2mp_iow_flags (m)); + } +#ifdef _WIN32if (tuntap_is_wintun (m->top.c1.tuntap)) {
@@ -429,14 +434,13 @@ }break ; -/* new incoming TCP client attempting to connect? */ case EVENT_ARG_LINK_SOCKET :if (!ev_arg->u.sock) {msg (D_MULTI_ERRORS ,"MULTI PROTOCOL: multi_proto_proc_io: null socket" );break ; } - +/* new incoming TCP client attempting to connect? */ if (!proto_is_dgram (ev_arg->u.sock->info.proto)) {socket_reset_listen_persistent (ev_arg->u.sock);
@@ -447,6 +451,11 @@ }break ; } +else + { +multi_process_io_udp (m, ev_arg->u.sock); +break ; + } } }else
src/openvpn/openvpn.h +2 -2
@@ -216,8 +216,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point(), \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +59 -7
130 lines not on this page · raw message
src/openvpn/options.h +3 -0
@@ -98,6 +98,7 @@ {const char *local;const char *port; +int proto; };struct connection_entry
@@ -915,6 +916,8 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
src/openvpn/socket.c +25 -3
@@ -1885,11 +1885,33 @@struct options *o = &c->options;ASSERT (sock); +const char *host = o->ce.local_list->array[sock_index]->local; +const char *port = o->ce.local_list->array[sock_index]->port; +int proto = o->ce.local_list->array[sock_index]->proto;const char *remote_host = o->ce.remote;const char *remote_port = o->ce.remote_port; - sock->local_host = o->ce.local_list->array[sock_index]->local; - sock->local_port = o->ce.local_list->array[sock_index]->port; +if (c->mode ==CM_CHILD_TCP || c->mode ==CM_CHILD_UDP ) + { +struct link_socket *tmp_sock =NULL ; +if (c->mode ==CM_CHILD_TCP ) + { + tmp_sock = (struct link_socket *)c->c2.accept_from; + } +else if (c->mode ==CM_CHILD_UDP ) + { + tmp_sock = c->c2.link_sockets[0 ]; + } + + host = tmp_sock->local_host; + port = tmp_sock->local_port; + proto = tmp_sock->info.proto; + } + +ASSERT (c->c2.link_sockets[sock_index]); + + sock->local_host = host; + sock->local_port = port; sock->remote_host = remote_host; sock->remote_port = remote_port; sock->dns_cache = c->c1.dns_cache;
@@ -1917,7 +1939,7 @@ sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; + sock->info.proto = proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; sock->info.lsa = &c->c1.link_socket_addrs[sock_index];
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 10
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: its_Giaan, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Patch Set 10:
(4 comments)
Patchset:
PS10:
some initial comments
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/4b14a43b_444e9460 :
PS10, Line 331: * Return the io_wait() flags appropriate for any particular reason why this is moved up?
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/daecd6cc_2a7c62a8 :
PS10, Line 1000: for (int j = 0; j < e->local_list->len; j++)
not sure how useful that change is - we basically set the same environment variable len times, every time overwriting the previous one.
http://gerrit.openvpn.net/c/openvpn/+/764/comment/62ecf583_fdc89a37 :
PS10, Line 3833: if (!has_udp_in_local_list(o))
That's not really the right check - or the function is named badly. The check needs to be if (has_tcp_...) or if (!has_only_udp_...), no?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 10
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Mon, 30 Dec 2024 19:28:08 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to look at the new patch set (#11).
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Bind to multiple ipv4/ipv6 addresses
Enables the binding of multiple listen sockets based on the specified "--local" directives.
The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances.
There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mroute.c
M src/openvpn/mroute.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c
17 files changed, 499 insertions(+), 277 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/11
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +169 -1
188 lines not on this page · raw message
src/openvpn/forward.h +4 -0
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_protocol *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
src/openvpn/init.c +43 -28
165 lines not on this page · raw message
src/openvpn/mroute.c +1 -0
@@ -421,6 +421,7 @@ {buf_printf (&out,":%d" ,ntohs (maddr.v4.port)); } +buf_printf (&out,":%d" , maddr.proto); }break ;
src/openvpn/mroute.h +5 -1
@@ -201,6 +201,10 @@ {return false; } +if (a1->proto != a2->proto) + { +return false; + }if (a1->netbits != a2->netbits) {return false;
@@ -222,7 +226,7 @@static inline uint32_t mroute_addr_hash_len (const struct mroute_addr *a) { -return (uint32_t ) a->len +2 ; +return (uint32_t ) a->len +3 ; } static inline void
src/openvpn/mtcp.c +15 -92
123 lines not on this page · raw message
src/openvpn/mtcp.h +0 -11
@@ -50,17 +50,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_protocol *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +7 -89
126 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m,struct link_socket *ls);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +112 -23
196 lines not on this page · raw message
src/openvpn/multi.h +8 -6
@@ -206,6 +206,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -253,10 +254,8 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() +* This function calls the main event loop function +* on the transport protocols: * * @param top - Top-level context structure. */
@@ -269,7 +268,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
@@ -665,9 +664,12 @@ multi_process_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags) { struct multi_instance *mi = m->pending; +if (!mi) + { +return false; + }bool ret = true; -ASSERT (mi); #ifdef MULTI_DEBUG_EVENT_LOOP printf("%s -> TUN len=%d\n", id(mi),
src/openvpn/multi_io.c +11 -2
@@ -155,6 +155,11 @@ &m->top.c2.link_sockets[i]->ev_arg); } +if (has_udp_in_local_list (&m->top.options)) + { +get_io_flags_udp (&m->top, m->multi_io,p2mp_iow_flags (m)); + } +#ifdef _WIN32if (tuntap_is_wintun (m->top.c1.tuntap)) {
@@ -442,14 +447,13 @@ }break ; -/* new incoming TCP client attempting to connect? */ case EVENT_ARG_LINK_SOCKET :if (!ev_arg->u.sock) {msg (D_MULTI_ERRORS ,"MULTI PROTOCOL: multi_proto_proc_io: null socket" );break ; } - +/* new incoming TCP client attempting to connect? */ if (!proto_is_dgram (ev_arg->u.sock->info.proto)) {socket_reset_listen_persistent (ev_arg->u.sock);
@@ -460,6 +464,11 @@ }break ; } +else + { +multi_process_io_udp (m, ev_arg->u.sock); +break ; + } } }else
src/openvpn/openvpn.h +2 -2
@@ -216,8 +216,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point(), \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +89 -7
172 lines not on this page · raw message
src/openvpn/options.h +5 -0
@@ -98,6 +98,7 @@ {const char *local;const char *port; +int proto; };struct connection_entry
@@ -917,6 +918,10 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); + +bool has_tcp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
src/openvpn/socket.c +25 -3
@@ -1888,11 +1888,33 @@struct options *o = &c->options;ASSERT (sock); +const char *host = o->ce.local_list->array[sock_index]->local; +const char *port = o->ce.local_list->array[sock_index]->port; +int proto = o->ce.local_list->array[sock_index]->proto;const char *remote_host = o->ce.remote;const char *remote_port = o->ce.remote_port; - sock->local_host = o->ce.local_list->array[sock_index]->local; - sock->local_port = o->ce.local_list->array[sock_index]->port; +if (c->mode ==CM_CHILD_TCP || c->mode ==CM_CHILD_UDP ) + { +struct link_socket *tmp_sock =NULL ; +if (c->mode ==CM_CHILD_TCP ) + { + tmp_sock = (struct link_socket *)c->c2.accept_from; + } +else if (c->mode ==CM_CHILD_UDP ) + { + tmp_sock = c->c2.link_sockets[0 ]; + } + + host = tmp_sock->local_host; + port = tmp_sock->local_port; + proto = tmp_sock->info.proto; + } + +ASSERT (c->c2.link_sockets[sock_index]); + + sock->local_host = host; + sock->local_port = port; sock->remote_host = remote_host; sock->remote_port = remote_port; sock->dns_cache = c->c1.dns_cache;
@@ -1920,7 +1942,7 @@ sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; + sock->info.proto = proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; sock->info.lsa = &c->c1.link_socket_addrs[sock_index];
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 11
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: cron2, plaisthos.
its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Patch Set 11:
(3 comments)
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/28aa0c26_868ac69b :
PS10, Line 331: * Return the io_wait() flags appropriate for
Quoted 1 line
any particular reason why this is moved up?
just a leftover.
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/3d99bd65_c221426a :
PS10, Line 1000: for (int j = 0; j < e->local_list->len; j++)
Quoted 1 line
not sure how useful that change is - we basically set the same environment variable
lentimes, eve […]
made another function to do this specifically for every local_entry, let me know if this is legal.
http://gerrit.openvpn.net/c/openvpn/+/764/comment/9afa3ab7_df013376 :
PS10, Line 3833: if (!has_udp_in_local_list(o))
Quoted 1 line
That's not really the right check - or the function is named badly. […]
made another function has_tcp_in_local_list(), might be useful in some cases, also I moved this check little bit down to when we have at least one local_entry, again, let me know if this is legal
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 11
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Comment-Date: Thu, 09 Jan 2025 13:52:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to look at the new patch set (#14).
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Bind to multiple ipv4/ipv6 addresses
Enables the binding of multiple listen sockets based on the specified "--local" directives.
The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances.
There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mroute.c
M src/openvpn/mroute.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c
17 files changed, 497 insertions(+), 275 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/14
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +169 -1
188 lines not on this page · raw message
src/openvpn/forward.h +4 -0
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
src/openvpn/init.c +43 -28
165 lines not on this page · raw message
src/openvpn/mroute.c +1 -0
@@ -421,6 +421,7 @@ {buf_printf (&out,":%d" ,ntohs (maddr.v4.port)); } +buf_printf (&out,":%d" , maddr.proto); }break ;
src/openvpn/mroute.h +5 -1
@@ -201,6 +201,10 @@ {return false; } +if (a1->proto != a2->proto) + { +return false; + }if (a1->netbits != a2->netbits) {return false;
@@ -222,7 +226,7 @@static inline uint32_t mroute_addr_hash_len (const struct mroute_addr *a) { -return (uint32_t ) a->len +2 ; +return (uint32_t ) a->len +3 ; } static inline void
src/openvpn/mtcp.c +14 -91
120 lines not on this page · raw message
src/openvpn/mtcp.h +0 -11
@@ -50,17 +50,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_io *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +6 -88
123 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m,struct link_socket *ls);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +112 -23
196 lines not on this page · raw message
src/openvpn/multi.h +8 -6
@@ -206,6 +206,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -253,10 +254,8 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() +* This function calls the main event loop function +* on the transport protocols: * * @param top - Top-level context structure. */
@@ -269,7 +268,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
@@ -665,9 +664,12 @@ multi_process_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags) { struct multi_instance *mi = m->pending; +if (!mi) + { +return false; + }bool ret = true; -ASSERT (mi); #ifdef MULTI_DEBUG_EVENT_LOOP printf("%s -> TUN len=%d\n", id(mi),
src/openvpn/multi_io.c +11 -2
@@ -155,6 +155,11 @@ &m->top.c2.link_sockets[i]->ev_arg); } +if (has_udp_in_local_list (&m->top.options)) + { +get_io_flags_udp (&m->top, m->multi_io,p2mp_iow_flags (m)); + } +#ifdef _WIN32if (tuntap_is_wintun (m->top.c1.tuntap)) {
@@ -442,14 +447,13 @@ }break ; -/* new incoming TCP client attempting to connect? */ case EVENT_ARG_LINK_SOCKET :if (!ev_arg->u.sock) {msg (D_MULTI_ERRORS ,"MULTI IO: multi_io_proc_io: null socket" );break ; } - +/* new incoming TCP client attempting to connect? */ if (!proto_is_dgram (ev_arg->u.sock->info.proto)) {socket_reset_listen_persistent (ev_arg->u.sock);
@@ -460,6 +464,11 @@ }break ; } +else + { +multi_process_io_udp (m, ev_arg->u.sock); +break ; + } } }else
src/openvpn/openvpn.h +2 -2
@@ -216,8 +216,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point(), \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +89 -7
172 lines not on this page · raw message
src/openvpn/options.h +5 -0
@@ -98,6 +98,7 @@ {const char *local;const char *port; +int proto; };struct connection_entry
@@ -917,6 +918,10 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); + +bool has_tcp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
src/openvpn/socket.c +25 -3
@@ -1888,11 +1888,33 @@struct options *o = &c->options;ASSERT (sock); +const char *host = o->ce.local_list->array[sock_index]->local; +const char *port = o->ce.local_list->array[sock_index]->port; +int proto = o->ce.local_list->array[sock_index]->proto;const char *remote_host = o->ce.remote;const char *remote_port = o->ce.remote_port; - sock->local_host = o->ce.local_list->array[sock_index]->local; - sock->local_port = o->ce.local_list->array[sock_index]->port; +if (c->mode ==CM_CHILD_TCP || c->mode ==CM_CHILD_UDP ) + { +struct link_socket *tmp_sock =NULL ; +if (c->mode ==CM_CHILD_TCP ) + { + tmp_sock = (struct link_socket *)c->c2.accept_from; + } +else if (c->mode ==CM_CHILD_UDP ) + { + tmp_sock = c->c2.link_sockets[0 ]; + } + + host = tmp_sock->local_host; + port = tmp_sock->local_port; + proto = tmp_sock->info.proto; + } + +ASSERT (c->c2.link_sockets[sock_index]); + + sock->local_host = host; + sock->local_port = port; sock->remote_host = remote_host; sock->remote_port = remote_port; sock->dns_cache = c->c1.dns_cache;
@@ -1920,7 +1942,7 @@ sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; + sock->info.proto = proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; sock->info.lsa = &c->c1.link_socket_addrs[sock_index];
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 14
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: its_Giaan, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Bind to multiple ipv4/ipv6 addresses
......................................................................
Patch Set 14: Code-Review-1
(1 comment)
Patchset:
PS14:
This needs a better commit message - it says "Bind to multiple ipv4/ipv6 addresses" but that is already introduced by #463 (which does not only populate local_entry but actually does the bind() as well).
So maybe something about "add support for simultaneous use of UDP and TCP sockets", and in the text something about "... and add all the bound sockets to the event loop".
Also, Gerrit claims a merge conflict...
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 14
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Thu, 23 Jan 2025 17:57:52 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: cron2, its_Giaan, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to look at the new patch set (#15).
The following approvals got outdated and were removed:
Code-Review-1 by cron2
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Add support for simultaneous use of UDP and TCP sockets
Add all the bound sockets to the event loop.
The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances.
There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mroute.c
M src/openvpn/mroute.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c
17 files changed, 496 insertions(+), 274 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/15
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +169 -1
188 lines not on this page · raw message
src/openvpn/forward.h +4 -0
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
src/openvpn/init.c +43 -28
165 lines not on this page · raw message
src/openvpn/mroute.c +1 -0
@@ -421,6 +421,7 @@ {buf_printf (&out,":%d" ,ntohs (maddr.v4.port)); } +buf_printf (&out,":%d" , maddr.proto); }break ;
src/openvpn/mroute.h +4 -0
@@ -210,6 +210,10 @@ {return false; } +if (a1->proto != a2->proto) + { +return false; + }if (a1->netbits != a2->netbits) {return false;
src/openvpn/mtcp.c +14 -91
120 lines not on this page · raw message
src/openvpn/mtcp.h +0 -11
@@ -50,17 +50,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_io *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +6 -88
123 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m,struct link_socket *ls);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +112 -23
196 lines not on this page · raw message
src/openvpn/multi.h +8 -6
@@ -204,6 +204,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -251,10 +252,8 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() +* This function calls the main event loop function +* on the transport protocols: * * @param top - Top-level context structure. */
@@ -267,7 +266,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
@@ -663,9 +662,12 @@ multi_process_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags) { struct multi_instance *mi = m->pending; +if (!mi) + { +return false; + }bool ret = true; -ASSERT (mi); #ifdef MULTI_DEBUG_EVENT_LOOP printf("%s -> TUN len=%d\n", id(mi),
src/openvpn/multi_io.c +11 -2
@@ -155,6 +155,11 @@ &m->top.c2.link_sockets[i]->ev_arg); } +if (has_udp_in_local_list (&m->top.options)) + { +get_io_flags_udp (&m->top, m->multi_io,p2mp_iow_flags (m)); + } +#ifdef _WIN32if (tuntap_is_wintun (m->top.c1.tuntap)) {
@@ -442,14 +447,13 @@ }break ; -/* new incoming TCP client attempting to connect? */ case EVENT_ARG_LINK_SOCKET :if (!ev_arg->u.sock) {msg (D_MULTI_ERRORS ,"MULTI IO: multi_io_proc_io: null socket" );break ; } - +/* new incoming TCP client attempting to connect? */ if (!proto_is_dgram (ev_arg->u.sock->info.proto)) {socket_reset_listen_persistent (ev_arg->u.sock);
@@ -460,6 +464,11 @@ }break ; } +else + { +multi_process_io_udp (m, ev_arg->u.sock); +break ; + } } }else
src/openvpn/openvpn.h +2 -2
@@ -216,8 +216,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point(), \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +89 -7
172 lines not on this page · raw message
src/openvpn/options.h +5 -0
@@ -98,6 +98,7 @@ {const char *local;const char *port; +int proto; };struct connection_entry
@@ -917,6 +918,10 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); + +bool has_tcp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
src/openvpn/socket.c +25 -3
@@ -1888,11 +1888,33 @@struct options *o = &c->options;ASSERT (sock); +const char *host = o->ce.local_list->array[sock_index]->local; +const char *port = o->ce.local_list->array[sock_index]->port; +int proto = o->ce.local_list->array[sock_index]->proto;const char *remote_host = o->ce.remote;const char *remote_port = o->ce.remote_port; - sock->local_host = o->ce.local_list->array[sock_index]->local; - sock->local_port = o->ce.local_list->array[sock_index]->port; +if (c->mode ==CM_CHILD_TCP || c->mode ==CM_CHILD_UDP ) + { +struct link_socket *tmp_sock =NULL ; +if (c->mode ==CM_CHILD_TCP ) + { + tmp_sock = (struct link_socket *)c->c2.accept_from; + } +else if (c->mode ==CM_CHILD_UDP ) + { + tmp_sock = c->c2.link_sockets[0 ]; + } + + host = tmp_sock->local_host; + port = tmp_sock->local_port; + proto = tmp_sock->info.proto; + } + +ASSERT (c->c2.link_sockets[sock_index]); + + sock->local_host = host; + sock->local_port = port; sock->remote_host = remote_host; sock->remote_port = remote_port; sock->dns_cache = c->c1.dns_cache;
@@ -1920,7 +1942,7 @@ sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; + sock->info.proto = proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; sock->info.lsa = &c->c1.link_socket_addrs[sock_index];
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 15
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: cron2, its_Giaan, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to look at the new patch set (#17).
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Add support for simultaneous use of UDP and TCP sockets
Add all the bound sockets to the event loop.
The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances.
There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mroute.c
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c
16 files changed, 491 insertions(+), 274 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/17
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +169 -1
188 lines not on this page · raw message
src/openvpn/forward.h +4 -0
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
src/openvpn/init.c +43 -28
165 lines not on this page · raw message
src/openvpn/mroute.c +1 -0
@@ -421,6 +421,7 @@ {buf_printf (&out,":%d" ,ntohs (maddr.v4.port)); } +buf_printf (&out,":%d" , maddr.proto); }break ;
src/openvpn/mtcp.c +14 -91
120 lines not on this page · raw message
src/openvpn/mtcp.h +0 -11
@@ -50,17 +50,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_io *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +6 -88
123 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m,struct link_socket *ls);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +111 -23
189 lines not on this page · raw message
src/openvpn/multi.h +8 -6
@@ -204,6 +204,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -251,10 +252,8 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() +* This function calls the main event loop function +* on the transport protocols: * * @param top - Top-level context structure. */
@@ -267,7 +266,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
@@ -663,9 +662,12 @@ multi_process_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags) { struct multi_instance *mi = m->pending; +if (!mi) + { +return false; + }bool ret = true; -ASSERT (mi); #ifdef MULTI_DEBUG_EVENT_LOOP printf("%s -> TUN len=%d\n", id(mi),
src/openvpn/multi_io.c +11 -2
@@ -155,6 +155,11 @@ &m->top.c2.link_sockets[i]->ev_arg); } +if (has_udp_in_local_list (&m->top.options)) + { +get_io_flags_udp (&m->top, m->multi_io,p2mp_iow_flags (m)); + } +#ifdef _WIN32if (tuntap_is_wintun (m->top.c1.tuntap)) {
@@ -442,14 +447,13 @@ }break ; -/* new incoming TCP client attempting to connect? */ case EVENT_ARG_LINK_SOCKET :if (!ev_arg->u.sock) {msg (D_MULTI_ERRORS ,"MULTI IO: multi_io_proc_io: null socket" );break ; } - +/* new incoming TCP client attempting to connect? */ if (!proto_is_dgram (ev_arg->u.sock->info.proto)) {socket_reset_listen_persistent (ev_arg->u.sock);
@@ -460,6 +464,11 @@ }break ; } +else + { +multi_process_io_udp (m, ev_arg->u.sock); +break ; + } } }else
src/openvpn/openvpn.h +2 -2
@@ -216,8 +216,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point(), \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +89 -7
172 lines not on this page · raw message
src/openvpn/options.h +5 -0
@@ -98,6 +98,7 @@ {const char *local;const char *port; +int proto; };struct connection_entry
@@ -917,6 +918,10 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); + +bool has_tcp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
src/openvpn/socket.c +25 -3
@@ -1888,11 +1888,33 @@struct options *o = &c->options;ASSERT (sock); +const char *host = o->ce.local_list->array[sock_index]->local; +const char *port = o->ce.local_list->array[sock_index]->port; +int proto = o->ce.local_list->array[sock_index]->proto;const char *remote_host = o->ce.remote;const char *remote_port = o->ce.remote_port; - sock->local_host = o->ce.local_list->array[sock_index]->local; - sock->local_port = o->ce.local_list->array[sock_index]->port; +if (c->mode ==CM_CHILD_TCP || c->mode ==CM_CHILD_UDP ) + { +struct link_socket *tmp_sock =NULL ; +if (c->mode ==CM_CHILD_TCP ) + { + tmp_sock = (struct link_socket *)c->c2.accept_from; + } +else if (c->mode ==CM_CHILD_UDP ) + { + tmp_sock = c->c2.link_sockets[0 ]; + } + + host = tmp_sock->local_host; + port = tmp_sock->local_port; + proto = tmp_sock->info.proto; + } + +ASSERT (c->c2.link_sockets[sock_index]); + + sock->local_host = host; + sock->local_port = port; sock->remote_host = remote_host; sock->remote_port = remote_port; sock->dns_cache = c->c1.dns_cache;
@@ -1920,7 +1942,7 @@ sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; + sock->info.proto = proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; sock->info.lsa = &c->c1.link_socket_addrs[sock_index];
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 17
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Patch Set 17:
(4 comments)
Patchset:
PS17:
some first comments and questions
File src/openvpn/forward.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/65aa7624_6dd5ee39 :
PS17, Line 2471:
spurious new line
File src/openvpn/mtcp.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/2164b42d_ffbff47e :
PS17, Line 57: if (mi && !proto_is_dgram(ls->info.proto))
why would this be called for an UDP packet in the first place, that is, why is that check necessary?
http://gerrit.openvpn.net/c/openvpn/+/764/comment/c70f7c01_8761d3d9 :
PS17, Line 156: if (proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto))
same here: why is this check necessary? Who calls a _tcp_ function for UDP packets, and why?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 17
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Fri, 24 Jan 2025 21:20:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Patch Set 17:
(12 comments)
Patchset:
PS17:
more comments
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/e1ebc360_490d6327 :
PS17, Line 3834:
this (and the next) blank line are arguably good, and should be kept, no?
http://gerrit.openvpn.net/c/openvpn/+/764/comment/8b76c90d_17966fbf :
PS17, Line 228: if (ce->proto != PROTO_TCP && c->mode != CM_CHILD_TCP)
what's the reason for this change? the conditions should be the same?
http://gerrit.openvpn.net/c/openvpn/+/764/comment/9a35e34d_80fa4240 :
PS17, Line 616: c->options.ce.proto = proto;
this does not look right. So we advance to the next ce, but keep the proto? Wouldn't that break
``` <connection> remote ... udp <connection> remote ... tcp ```
setups?
http://gerrit.openvpn.net/c/openvpn/+/764/comment/d8380160_cf33bdd0 :
PS17, Line 2687: if (!proto_is_udp(c->c2.link_sockets[0]->info.proto) && c->options.ce.explicit_exit_notification)
this like is getting a bit long, so I think wrapping might be a good thing
http://gerrit.openvpn.net/c/openvpn/+/764/comment/e84b95dc_73633f8a :
PS17, Line 2846: if (has_udp_in_local_list(&c->options))
this might be modelling the existing behaviour, but it's arguable whether the old behaviour was actually correct - a *server* should not do exponential backoff after a connection failure, no matter whether TCP or UDP.
http://gerrit.openvpn.net/c/openvpn/+/764/comment/ff1ffcf7_a5d0582f :
PS17, Line 3369: }
given that link_socket_proto_connection_oriented() (nowadays) is a very long form of if (!proto_is_dgram()) I don't think it makes sense to have the code this way - get rid of the if(), loop always.
That said, grepping through the code, to.tcp_mode seems to be dead anyway - I see no user of it. Get rid of it completely, then ;-)
File src/openvpn/mroute.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/e768a558_8ea1565c :
PS17, Line 424: buf_printf(&out, ":%d", maddr.proto);
we should not unconditionally add this :%d. It might be useful, but when MR_WITH_PORT is not set, it very much looks like :6 or :17 being the remote port.
If we really want this, we should ascii-ize the proto and prepend (tcp:1.2.3.4:1194), no?
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/cf0b5a07_5892252f :
PS17, Line 1052: setenv_local_entry(es, o->ce.local_list->array[i], i+1);
you have an i+1 here, and another i+1 inside setenv_local_entry()... what is it that you want to achieve here?
http://gerrit.openvpn.net/c/openvpn/+/764/comment/2b3f667b_e3b3e51c :
PS17, Line 3192: o->ce.proto = ce->proto;
what is o->ce.proto?
http://gerrit.openvpn.net/c/openvpn/+/764/comment/1bf199d4_7737bca5 :
PS17, Line 3198: if (ce->local_list->array[i]->proto == PROTO_TCP)
So we walk the list here, for the --server case, and then walk it again in option_postprocess_mutate() for all cases, correct? So we could just store the desired proto (TCP_SERVER etc) in o->ce.proto here and leave the walking the list to option_postprocess_mutate()?
http://gerrit.openvpn.net/c/openvpn/+/764/comment/4ee90666_8e61c48d :
PS17, Line 3838: msg(M_INFO, "NOTE: --fast-io is disabled while using multi-socket");
that comment needs to be something like --fast-ip is disabled if there is a TCP socket active or so ("using multi-socket" with multiple UDP sockets won't be a problem)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 17
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Fri, 24 Jan 2025 21:50:41 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: cron2, its_Giaan, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Patch Set 17:
(1 comment)
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/a9230923_28af6cf8 :
PS17, Line 2846: if (has_udp_in_local_list(&c->options))
Quoted 1 line
this might be modelling the existing behaviour, but it's arguable whether the old behaviour was actu […]
maybe something to create a ticket about and we fix it separately from this patchset? It may alone lead to HUGECANOFWORMS².
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 17
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Wed, 29 Jan 2025 15:06:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: cron2, its_Giaan, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to look at the new patch set (#18).
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Add support for simultaneous use of UDP and TCP sockets
Add all the bound sockets to the event loop.
The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances.
There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c
M src/openvpn/ssl_common.h
16 files changed, 455 insertions(+), 265 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/18
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +168 -1
181 lines not on this page · raw message
src/openvpn/forward.h +4 -0
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
src/openvpn/init.c +26 -25
126 lines not on this page · raw message
src/openvpn/mtcp.c +0 -84
87 lines not on this page · raw message
src/openvpn/mtcp.h +0 -11
@@ -50,17 +50,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_io *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +6 -88
123 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m,struct link_socket *ls);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +111 -23
189 lines not on this page · raw message
src/openvpn/multi.h +8 -6
@@ -204,6 +204,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -251,10 +252,8 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() +* This function calls the main event loop function +* on the transport protocols: * * @param top - Top-level context structure. */
@@ -267,7 +266,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
@@ -663,9 +662,12 @@ multi_process_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags) { struct multi_instance *mi = m->pending; +if (!mi) + { +return false; + }bool ret = true; -ASSERT (mi); #ifdef MULTI_DEBUG_EVENT_LOOP printf("%s -> TUN len=%d\n", id(mi),
src/openvpn/multi_io.c +11 -2
@@ -155,6 +155,11 @@ &m->top.c2.link_sockets[i]->ev_arg); } +if (has_udp_in_local_list (&m->top.options)) + { +get_io_flags_udp (&m->top, m->multi_io,p2mp_iow_flags (m)); + } +#ifdef _WIN32if (tuntap_is_wintun (m->top.c1.tuntap)) {
@@ -442,14 +447,13 @@ }break ; -/* new incoming TCP client attempting to connect? */ case EVENT_ARG_LINK_SOCKET :if (!ev_arg->u.sock) {msg (D_MULTI_ERRORS ,"MULTI IO: multi_io_proc_io: null socket" );break ; } - +/* new incoming TCP client attempting to connect? */ if (!proto_is_dgram (ev_arg->u.sock->info.proto)) {socket_reset_listen_persistent (ev_arg->u.sock);
@@ -460,6 +464,11 @@ }break ; } +else + { +multi_process_io_udp (m, ev_arg->u.sock); +break ; + } } }else
src/openvpn/openvpn.h +2 -2
@@ -216,8 +216,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point(), \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +86 -7
172 lines not on this page · raw message
src/openvpn/options.h +5 -0
@@ -98,6 +98,7 @@ {const char *local;const char *port; +int proto; };struct connection_entry
@@ -917,6 +918,10 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); + +bool has_tcp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
src/openvpn/socket.c +25 -3
@@ -1888,11 +1888,33 @@struct options *o = &c->options;ASSERT (sock); +const char *host = o->ce.local_list->array[sock_index]->local; +const char *port = o->ce.local_list->array[sock_index]->port; +int proto = o->ce.local_list->array[sock_index]->proto;const char *remote_host = o->ce.remote;const char *remote_port = o->ce.remote_port; - sock->local_host = o->ce.local_list->array[sock_index]->local; - sock->local_port = o->ce.local_list->array[sock_index]->port; +if (c->mode ==CM_CHILD_TCP || c->mode ==CM_CHILD_UDP ) + { +struct link_socket *tmp_sock =NULL ; +if (c->mode ==CM_CHILD_TCP ) + { + tmp_sock = (struct link_socket *)c->c2.accept_from; + } +else if (c->mode ==CM_CHILD_UDP ) + { + tmp_sock = c->c2.link_sockets[0 ]; + } + + host = tmp_sock->local_host; + port = tmp_sock->local_port; + proto = tmp_sock->info.proto; + } + +ASSERT (c->c2.link_sockets[sock_index]); + + sock->local_host = host; + sock->local_port = port; sock->remote_host = remote_host; sock->remote_port = remote_port; sock->dns_cache = c->c1.dns_cache;
@@ -1920,7 +1942,7 @@ sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; + sock->info.proto = proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; sock->info.lsa = &c->c1.link_socket_addrs[sock_index];
src/openvpn/ssl_common.h +0 -1
@@ -363,7 +363,6 @@int replay_window;/* --replay-window parm */ int replay_time;/* --replay-window parm */ -bool tcp_mode;const char *config_ciphername;const char *config_ncp_ciphers;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 18
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: cron2, plaisthos.
its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Patch Set 17:
(13 comments)
File src/openvpn/forward.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/d2d2bf21_d4657dec :
PS17, Line 2471:
Quoted 1 line
spurious new line
Done
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/557e83eb_4b361d4d :
PS17, Line 3834:
Quoted 1 line
this (and the next) blank line are arguably good, and should be kept, no?
Done
http://gerrit.openvpn.net/c/openvpn/+/764/comment/e3883fac_7a141a70 :
PS17, Line 228: if (ce->proto != PROTO_TCP && c->mode != CM_CHILD_TCP)
Quoted 1 line
what's the reason for this change? the conditions should be the same?
Done
http://gerrit.openvpn.net/c/openvpn/+/764/comment/098aad10_d6ea2c6c :
PS17, Line 616: c->options.ce.proto = proto;
Quoted 1 line
this does not look right. So we advance to the next ce, but keep the proto? Wouldn't that break […]
Done
http://gerrit.openvpn.net/c/openvpn/+/764/comment/d2412021_82123c38 :
PS17, Line 2687: if (!proto_is_udp(c->c2.link_sockets[0]->info.proto) && c->options.ce.explicit_exit_notification)
Quoted 1 line
this like is getting a bit long, so I think wrapping might be a good thing
Done
http://gerrit.openvpn.net/c/openvpn/+/764/comment/d9a8ec74_c1f662c7 :
PS17, Line 3369: }
Quoted 1 line
given that
link_socket_proto_connection_oriented()(nowadays) is a very long form of `if (!proto_i […]
Done
File src/openvpn/mroute.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/8b5bd492_5d35e8a3 :
PS17, Line 424: buf_printf(&out, ":%d", maddr.proto);
Quoted 1 line
we should not unconditionally add this
:%d. […]
Done
File src/openvpn/mtcp.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/e4035612_308aec8e :
PS17, Line 57: if (mi && !proto_is_dgram(ls->info.proto))
Quoted 1 line
why would this be called for an UDP packet in the first place, that is, why is that check necessary?
that's a leftover from early development when still trying to untangle udp and tcp clients.
http://gerrit.openvpn.net/c/openvpn/+/764/comment/74a66627_6f73d597 :
PS17, Line 156: if (proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto))
Quoted 1 line
same here: why is this check necessary? Who calls a
_tcp_function for UDP packets, and why?
see answer above
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/f9770527_5f1c061a :
PS17, Line 1052: setenv_local_entry(es, o->ce.local_list->array[i], i+1);
Quoted 1 line
you have an i+1 here, and another i+1 inside
setenv_local_entry()... […]
i'm not sure either
http://gerrit.openvpn.net/c/openvpn/+/764/comment/bb8e11ad_17fcd75d :
PS17, Line 3192: o->ce.proto = ce->proto;
Quoted 1 line
what is `o->ce. […]
o->ce differs from let's say o->connection_list->array[0] but this is not a big deal on server side while it can be dangerous on client side so a copy won't hurt.
http://gerrit.openvpn.net/c/openvpn/+/764/comment/efef2d42_e743e796 :
PS17, Line 3198: if (ce->local_list->array[i]->proto == PROTO_TCP)
Quoted 1 line
So we walk the list here, for the
--servercase, and then walk it again in `option_postprocess_mut […]
Done
http://gerrit.openvpn.net/c/openvpn/+/764/comment/809120a8_8e4a8ed5 :
PS17, Line 3838: msg(M_INFO, "NOTE: --fast-io is disabled while using multi-socket");
Quoted 1 line
that comment needs to be something like
--fast-ip is disabled if there is a TCP socket activeor s […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 17
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Comment-Date: Fri, 31 Jan 2025 10:42:34 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, ordex, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Patch Set 18: Code-Review-1
(23 comments)
Patchset:
PS18:
some minor bits, and something I consider major - massive code duplication that is not helping to make the code flow easier to understand
File doc/man-sections/link-options.rst:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/37a21a77_b85f0053 :
PS18, Line 122:
I think we also should mention the default values, something like
``` If ``port`` is omitted, it defaults to the setting of ``--lport``. If ``proto`` is omitted, it defaults to the setting of ``--proto``. ```
... which brings up an interesting corner case, what if a config has
``` local * 1000 tcp remote 1.2.3.4 1194 udp ```
? Shall we just disallow proto bindings on the client-side?
File src/openvpn/forward.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/6695b917_b3e1ecda :
PS18, Line 2077: if (flags & IOW_WAIT_SIGNAL)
this is duplicating a huge chunk of code from io_wait_dowork() - which is hard enough to read, without appearing twice.
Can you remove the common parts from io_wait_dowork() and have it call here?
http://gerrit.openvpn.net/c/openvpn/+/764/comment/f3a3f9ad_e4a8f66f :
PS18, Line 2184: if (c->c2.fast_io && (flags & (IOW_TO_TUN | IOW_TO_LINK | IOW_MBUF)))
this function is mostly identical to forward.h::io_wait(), except for the call to get_io_flags_dowork_udp() in the end, vs. io_wait_dowork(), and setting multi_io->udp_flags vs. c->c2.event_set_status.
There has to be a better way to tackle this than to walk all sockets twice, in two nearly identical functions. Why's there a separate udp_flags and event_set_status anyway?
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/bf3f0236_95dbba2c :
PS17, Line 2846: if (has_udp_in_local_list(&c->options))
Quoted 1 line
maybe something to create a ticket about and we fix it separately from this patchset? […]
Well, this is introducing new code, to model behaviour that was not intentional in the first place. So I'd go for simple code - on a server, no matter of UDP or TCP, delay 1 second, on a client, do exponential backoff.
Also, arguably, the code proposed isn't doing the right thing anyway - it's doing "if there is *one* UDP socket, among many, do backoff (on UDP and TCP sockets), and if there are *only* TCP sockets, not".
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/286fdebf_e60bf789 :
PS18, Line 2685: if (!proto_is_udp(c->c2.link_sockets[0]->info.proto)
maybe add a de-confusing comment like /* client side = only one link_socket */ or so... I was wondering, again, why there is no loop here...
File src/openvpn/mtcp.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/ed3a23f0_5a81d266 :
PS17, Line 57: if (mi && !proto_is_dgram(ls->info.proto))
Quoted 1 line
that's a leftover from early development when still trying to untangle udp and tcp clients.
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/764/comment/7810367d_c39b0d92 :
PS17, Line 156: if (proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto))
Quoted 1 line
see answer above
Acknowledged
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/e0aa2662_4a802ef8 :
PS18, Line 335: const unsigned int status = m->multi_io->udp_flags;
I do wonder why a separate udp_flags field for UDP has been introduced. Isn't this basically mimicking everything we do in event_set_status for TCP? Where is the practical difference (except we have two mostly-identical functions that set udp_flags or event_set_status)?
File src/openvpn/multi.h:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/b5407429_3ff1a65d :
PS18, Line 670:
how can this ever be called without valid mi? Shouldn't this be flagged as a hard error, like keeping the ASSERT(mi)?
File src/openvpn/multi.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/c2b835ed_a70ba824 :
PS18, Line 609: bool is_dgram = proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto);
Is this for a (single-socket) client instance? Again we have a confused reader wondering why we only look at link_sockets[0]... ;-)
http://gerrit.openvpn.net/c/openvpn/+/764/comment/35e37e61_90cb74af :
PS18, Line 3841: if (!mi->halt && proto_is_dgram(mi->context.options.ce.proto))
why is this using mi->context.options.ce.proto? The rest of the code seems to have moved all the checks toward something ls->proto - is this not available here?
http://gerrit.openvpn.net/c/openvpn/+/764/comment/9539d5ff_a442fabf :
PS18, Line 3879: else if (has_udp_in_local_list(&m->top.options))
why are you splitting this condition into two nested if()? I can see changing proto_is_dgram() to has_udp_...() but it could just be part of the same if (...&...&...) block. no?
http://gerrit.openvpn.net/c/openvpn/+/764/comment/82416e50_ccc42bb0 :
PS18, Line 4164: * Main event loop for OpenVPN in multi-protocol server mode.
I'd remove the "multi-protocol" part (protocols, again) - maybe name this point-to-multipoint server mode instead, so it's clear "this is the --server functionality".
http://gerrit.openvpn.net/c/openvpn/+/764/comment/0808d8b9_ee6cdc19 :
PS18, Line 4169: void
static?
http://gerrit.openvpn.net/c/openvpn/+/764/comment/9c492ef1_466fc2d6 :
PS18, Line 4265: }
I don't like this construct - now tunnel_server_init() is doing all the work (init, call loop, uninit).
I suggest to remove tunnel_server_init() and have all its functionality in tunnel_server().
Having the inner loop in tunnel_server_loop() is fine for me.
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/3fed854f_635a4c70 :
PS10, Line 1000: for (int j = 0; j < e->local_list->len; j++)
Quoted 1 line
made another function to do this specifically for every
local_entry, let me know if this is legal.
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/764/comment/bed3e7ba_f462f4f9 :
PS10, Line 3833: if (!has_udp_in_local_list(o))
Quoted 1 line
made another function
has_tcp_in_local_list(), might be useful in some cases, also I moved this chec […]
Acknowledged
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/b093c46d_db331cc3 :
PS17, Line 1052: setenv_local_entry(es, o->ce.local_list->array[i], i+1);
Quoted 1 line
i'm not sure either
so only one "i+1" left - that means local_list entries are numbered 0...(n-1) and the env variables are numbered 1...n - which makes sense.
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/231e4ca1_8cdb4f3f :
PS18, Line 3351: if (!le->proto)
we have a comment for setting "port" and none for "proto". Do we want one?
http://gerrit.openvpn.net/c/openvpn/+/764/comment/ffe64598_39b97862 :
PS18, Line 3816: }
this extra loop looks like it really wants to be part of options_postprocess_mutate_le(), no?
http://gerrit.openvpn.net/c/openvpn/+/764/comment/da8501e5_f0ca4bac :
PS18, Line 3839:
I'm actually not sure I understand fast_io well enough for this, but - what I understand, fast_io is only working on UDP sockets (and not if --shaper is active) - but why can't we not have fast_io on "all the UDP sockets" just because there is one extra TCP socket?
File src/openvpn/socket.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/2d46cfa3_40e4c922 :
PS18, Line 1914: ASSERT(c->c2.link_sockets[sock_index]);
we already have an ASSERT(sock) at the beginning, which is sock = c->c2.link_sockets[sock_index]; - so I think this can go?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 18
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Fri, 31 Jan 2025 13:32:25 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: its_Giaan <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: cron2, its_Giaan, ordex, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to look at the new patch set (#19).
The following approvals got outdated and were removed:
Code-Review-1 by cron2
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Add support for simultaneous use of UDP and TCP sockets
Add all the bound sockets to the event loop.
The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances.
There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/multi_io.h
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c
M src/openvpn/ssl_common.h
17 files changed, 404 insertions(+), 311 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/19
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +120 -40
191 lines not on this page · raw message
src/openvpn/forward.h +4 -0
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
src/openvpn/init.c +19 -24
119 lines not on this page · raw message
src/openvpn/mtcp.c +0 -98
107 lines not on this page · raw message
src/openvpn/mtcp.h +0 -13
@@ -40,8 +40,6 @@void multi_tcp_instance_specific_free (struct multi_instance *mi); -void multi_tcp_set_global_rw_flags (struct multi_context *m,struct multi_instance *mi); -bool multi_tcp_process_outgoing_link (struct multi_context *m,bool defer,const unsigned int mpp_flags);bool multi_tcp_process_outgoing_link_ready (struct multi_context *m,struct multi_instance *mi,const unsigned int mpp_flags);
@@ -50,17 +48,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_io *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +6 -88
123 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m,struct link_socket *ls);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +94 -14
166 lines not on this page · raw message
src/openvpn/multi.h +4 -5
@@ -204,6 +204,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -251,10 +252,8 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() +* This function calls the main event loop function +* on the transport protocols: * * @param top - Top-level context structure. */
@@ -267,7 +266,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
src/openvpn/multi_io.c +35 -4
@@ -133,6 +133,20 @@ }void +multi_io_set_global_rw_flags (struct multi_context *m,struct multi_instance *mi) +{ +if (mi) + { + mi->socket_set_called = true; +socket_set (mi->context.c2.link_sockets[0 ], + m->multi_io->es, +mbuf_defined (mi->tcp_link_out_deferred) ?EVENT_WRITE :EVENT_READ , + !proto_is_dgram (mi->context.c2.link_sockets[0 ]->info.proto) ? &mi->ev_arg : &mi->context.c2.link_sockets[0 ]->ev_arg, + !proto_is_dgram (mi->context.c2.link_sockets[0 ]->info.proto) ? &mi->tcp_rwflags :NULL ); + } +} + +void multi_io_free (struct multi_io *multi_io) {if (multi_io)
@@ -155,6 +169,11 @@ &m->top.c2.link_sockets[i]->ev_arg); } +if (has_udp_in_local_list (&m->top.options)) + { +get_io_flags_udp (&m->top, m->multi_io,p2mp_iow_flags (m)); + } +#ifdef _WIN32if (tuntap_is_wintun (m->top.c1.tuntap)) {
@@ -333,7 +352,7 @@case TA_INITIAL :ASSERT (mi); -multi_tcp_set_global_rw_flags (m, mi); +multi_io_set_global_rw_flags (m, mi);multi_process_post (m, mi, mpp_flags);break ;
@@ -383,7 +402,7 @@ }else { -multi_tcp_set_global_rw_flags (m, mi); +multi_io_set_global_rw_flags (m, mi); }break ;
@@ -442,14 +461,13 @@ }break ; -/* new incoming TCP client attempting to connect? */ case EVENT_ARG_LINK_SOCKET :if (!ev_arg->u.sock) {msg (D_MULTI_ERRORS ,"MULTI IO: multi_io_proc_io: null socket" );break ; } - +/* new incoming TCP client attempting to connect? */ if (!proto_is_dgram (ev_arg->u.sock->info.proto)) {socket_reset_listen_persistent (ev_arg->u.sock);
@@ -460,6 +478,19 @@ }break ; } +else + { +multi_process_io_udp (m, ev_arg->u.sock); + mi = m->pending; +/* Mimic TCP and monitor and/or handle events that +* are triggered in succession by the first one +* before returning to the main loop. */ +if (mi) + { +multi_io_action (m, mi,TA_INITIAL , false); + } +break ; + } } }else
src/openvpn/multi_io.h +2 -0
@@ -70,6 +70,8 @@void multi_io_process_io (struct multi_context *m); +void multi_io_set_global_rw_flags (struct multi_context *m,struct multi_instance *mi); +void multi_io_action (struct multi_context *m,struct multi_instance *mi,int action,bool poll);void multi_io_delete_event (struct multi_io *multi_io,event_t event);
src/openvpn/openvpn.h +2 -2
@@ -216,8 +216,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point(), \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +85 -7
171 lines not on this page · raw message
src/openvpn/options.h +5 -0
@@ -98,6 +98,7 @@ {const char *local;const char *port; +int proto; };struct connection_entry
@@ -917,6 +918,10 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); + +bool has_tcp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
src/openvpn/socket.c +25 -3
@@ -1888,11 +1888,33 @@struct options *o = &c->options;ASSERT (sock); +const char *host = o->ce.local_list->array[sock_index]->local; +const char *port = o->ce.local_list->array[sock_index]->port; +int proto = o->ce.local_list->array[sock_index]->proto;const char *remote_host = o->ce.remote;const char *remote_port = o->ce.remote_port; - sock->local_host = o->ce.local_list->array[sock_index]->local; - sock->local_port = o->ce.local_list->array[sock_index]->port; +if (c->mode ==CM_CHILD_TCP || c->mode ==CM_CHILD_UDP ) + { +struct link_socket *tmp_sock =NULL ; +if (c->mode ==CM_CHILD_TCP ) + { + tmp_sock = (struct link_socket *)c->c2.accept_from; + } +else if (c->mode ==CM_CHILD_UDP ) + { + tmp_sock = c->c2.link_sockets[0 ]; + } + + host = tmp_sock->local_host; + port = tmp_sock->local_port; + proto = tmp_sock->info.proto; + } + +ASSERT (c->c2.link_sockets[sock_index]); + + sock->local_host = host; + sock->local_port = port; sock->remote_host = remote_host; sock->remote_port = remote_port; sock->dns_cache = c->c1.dns_cache;
@@ -1920,7 +1942,7 @@ sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; + sock->info.proto = proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; sock->info.lsa = &c->c1.link_socket_addrs[sock_index];
src/openvpn/ssl_common.h +0 -1
@@ -362,7 +362,6 @@int replay_window;/* --replay-window parm */ int replay_time;/* --replay-window parm */ -bool tcp_mode;const char *config_ciphername;const char *config_ncp_ciphers;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 19
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: cron2, ordex, plaisthos.
its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Patch Set 18:
(15 comments)
File src/openvpn/forward.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/50e5e827_606d6e4d :
PS18, Line 2077: if (flags & IOW_WAIT_SIGNAL)
Quoted 1 line
this is duplicating a huge chunk of code from
io_wait_dowork()- which is hard enough to read, wit […]
Done
http://gerrit.openvpn.net/c/openvpn/+/764/comment/d0b6ff1d_733c10fb :
PS18, Line 2184: if (c->c2.fast_io && (flags & (IOW_TO_TUN | IOW_TO_LINK | IOW_MBUF)))
Quoted 1 line
this function is mostly identical to `forward. […]
The multi_io has no event_set_status member and since UDP require that I decided to call it udp_flags since it is UDP specific.
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/f536d12b_7a5c51e7 :
PS17, Line 2846: if (has_udp_in_local_list(&c->options))
Quoted 1 line
Well, this is introducing new code, to model behaviour that was not intentional in the first place. […]
Done
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/29430a8c_d3861afa :
PS18, Line 2685: if (!proto_is_udp(c->c2.link_sockets[0]->info.proto)
Quoted 1 line
maybe add a de-confusing comment like
/* client side = only one link_socket */or so... […]
Done
File src/openvpn/multi.h:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/cad1ca81_6565d700 :
PS18, Line 670:
Quoted 1 line
how can this ever be called without valid
mi? Shouldn't this be flagged as a hard error, like kee […]
Done
File src/openvpn/multi.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/6aa7274d_985a29c2 :
PS18, Line 609: bool is_dgram = proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto);
Quoted 1 line
Is this for a (single-socket) client instance? Again we have a confused reader wondering why we onl […]
It is, the 'mi' tells you that this is a client-instance context.
http://gerrit.openvpn.net/c/openvpn/+/764/comment/61d7a697_54c1c90d :
PS18, Line 3841: if (!mi->halt && proto_is_dgram(mi->context.options.ce.proto))
Quoted 1 line
why is this using `mi->context.options.ce. […]
Done
http://gerrit.openvpn.net/c/openvpn/+/764/comment/02b15a25_8acde395 :
PS18, Line 3879: else if (has_udp_in_local_list(&m->top.options))
Quoted 1 line
why are you splitting this condition into two nested
if()? I can see changingproto_is_dgram()[…]
Done
http://gerrit.openvpn.net/c/openvpn/+/764/comment/0f048603_319d08a4 :
PS18, Line 4164: * Main event loop for OpenVPN in multi-protocol server mode.
Quoted 1 line
I'd remove the "multi-protocol" part (protocols, again) - maybe name this `point-to-multipoint serve […]
Done
http://gerrit.openvpn.net/c/openvpn/+/764/comment/20464f08_18d9e039 :
PS18, Line 4169: void
Quoted 1 line
static?
Done
http://gerrit.openvpn.net/c/openvpn/+/764/comment/d0311291_8207b195 :
PS18, Line 4265: }
Quoted 1 line
I don't like this construct - now
tunnel_server_init()is doing all the work (init, call loop, uni […]
Done
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/cef8e785_9aa6185f :
PS18, Line 3351: if (!le->proto)
Quoted 1 line
we have a comment for setting "port" and none for "proto". […]
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/764/comment/c5c0f206_666146e4 :
PS18, Line 3816: }
Quoted 1 line
this extra loop looks like it really wants to be part of
options_postprocess_mutate_le(), no?
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/764/comment/611fa1ff_cab4dcb3 :
PS18, Line 3839:
Quoted 1 line
I'm actually not sure I understand
fast_iowell enough for this, but - what I understand, `fast_io […]
Acknowledged
File src/openvpn/socket.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/68eeaf4b_34101cc0 :
PS18, Line 1914: ASSERT(c->c2.link_sockets[sock_index]);
Quoted 1 line
we already have an
ASSERT(sock)at the beginning, which is `sock =c->c2. […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 18
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Fri, 14 Feb 2025 17:45:31 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, ordex, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Patch Set 19: Code-Review-1
(1 comment)
Patchset:
PS19:
I have not done a new round of review on the code yet, but tested it somewhat more in earnest :-)
Running well-behaved clients on multiple UDP and TCP ports in parallel (2 UDP, 1 TCP, changing ports, pinging around) worked very nicely.
Then I went for the gremlins - lots of short-lived connections on randomized destionation ports, with 4 sockets bound (2 UDP, 2 TCP), and *boom* it asserts on me, after about 5 minutes of gremlin run time...
``` 2025-02-18 17:20:55 us=391543 Connection Attempt Assertion failed at forward.c:1756 (link_socket_actual_defined(c->c2.to_link_addr)) ```
this is with DCO on the server, but I do not think it makes a difference - most likely this is a race condition because these clients are extremely non-well-behaved, read, some are killed right after TCP connection, or in the middle of the TLS handshake.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 19
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Tue, 18 Feb 2025 16:24:33 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, ordex, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Patch Set 19:
(1 comment)
Patchset:
PS19:
without DCO it also crashes, though it takes a bit longer. Might be just random chance of timing...
These are the last few lines
``` 2025-02-18 17:31:52 us=617953 tcp4-server:194.97.140.21:39821 TCPv4_SERVER READ [299] from [AF_INET]194.97.140.21:39821: P_CONTROL_V1 kid=0 [ 0 ] pid=1 DATA len=273 2025-02-18 17:31:52 us=628842 tcp4-server:194.97.140.21:39821 TCPv4_SERVER WRITE [1222] to [AF_INET]194.97.140.21:39821: P_CONTROL_V1 kid=0 [ 1 0 ] pid=1 DATA len=1192 2025-02-18 17:31:52 us=628925 tcp4-server:194.97.140.21:39821 TCPv4_SERVER WRITE [887] to [AF_INET]194.97.140.21:39821: P_CONTROL_V1 kid=0 [ 1 0 ] pid=2 DATA len=857 2025-02-18 17:31:52 us=629004 Connection Attempt Assertion failed at forward.c:1756 (link_socket_actual_defined(c->c2.to_link_addr)) 2025-02-18 17:31:52 us=629029 Connection Attempt Exiting due to fatal error 2025-02-18 17:31:52 us=629077 Connection Attempt Closing tun/tap interface ```
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 19
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Tue, 18 Feb 2025 16:33:06 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, ordex, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Patch Set 19: Code-Review-2
(10 comments)
Patchset:
PS19:
more comments, but these are mostly minor and/or nothing new. The main thing that must be fixed remains the gremlin crash...
File src/openvpn/multi.h:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/acd4850a_3fd5d5d9 :
PS19, Line 256: * on the transport protocols:
The wording is a bit odd... since we do no longer need to point out that this calls "tcp and udp!!" I'd just make this
``` * Main event loop for OpenVPN in server mode ```
(yes it will call tunnel_server_loop() but that's not really relevant here, is it?)
File src/openvpn/multi.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/002a17a2_4cb6329f :
PS18, Line 609: bool is_dgram = proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto);
Quoted 1 line
It is, the 'mi' tells you that this is a client-instance context.
Done
File src/openvpn/multi_io.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/4c1453d0_3cacda0f :
PS19, Line 145: !proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto) ? &mi->tcp_rwflags : NULL);
I like that this is being moved to a dedicated function :-) - I would style it differently, though, not "one fat function call with two conditionals in it".
Maybe start with if (!mi) { return; } (early return, save indent space) and then have a surrounding if(proto_is_dgram) { ...} with one socket_set() call in each branch?
... also, why are we not storing ev_arg in the &mi for both cases?
http://gerrit.openvpn.net/c/openvpn/+/764/comment/5d6f18e7_d50503ba :
PS19, Line 491: }
since this is the same if (mi) now, it could go outside one level, avoid code duplication... and make the comment "protocol invariant" (/* monitor and/or handle events that are triggered... without mentioning TCP)
File src/openvpn/openvpn.h:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/ce61719a_f2258f18 :
PS19, Line 219: * tunnel_point_to_point(), \c tunnel_server() \c
an and is missing before tunnel_server() (since it's only these 2 functions now)
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/3dbf2e3f_8940878c :
PS18, Line 3351: if (!le->proto)
Quoted 1 line
Acknowledged
it says acknowledged but we still have no comment for proto? ;-)
http://gerrit.openvpn.net/c/openvpn/+/764/comment/ad01e4f2_8599b78a :
PS18, Line 3839:
Quoted 1 line
Acknowledged
so what does "Acknowledged" mean, here? "Will be handled in a future patch"?
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/873691f9_0977c2fe :
PS19, Line 1747: o->local_list->array[i]->port);
I think this should show proto now as well, otherwise the log is a bit hard to read if trying to understand why a bind() fails.
File src/openvpn/socket.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/e7e767ef_7f49bef8 :
PS18, Line 1914: ASSERT(c->c2.link_sockets[sock_index]);
Quoted 1 line
Done
maybe gerrit is playing tricks on me, but the ASSERT() seems to be still here
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 19
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Tue, 18 Feb 2025 17:35:06 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: its_Giaan <[email protected]...>
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, ordex, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to look at the new patch set (#20).
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Add support for simultaneous use of UDP and TCP sockets
Add all the bound sockets to the event loop. The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances. There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/multi_io.h
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c
M src/openvpn/ssl_common.h
17 files changed, 426 insertions(+), 325 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/20
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +121 -41
192 lines not on this page · raw message
src/openvpn/forward.h +7 -2
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
@@ -367,12 +371,13 @@/* * This is the core I/O wait function, used for all I/O waits except -* for TCP in server mode. +* in server mode. */ static inline void io_wait (struct context *c,const unsigned int flags) { -if (c->c2.fast_io && (flags & (IOW_TO_TUN |IOW_TO_LINK |IOW_MBUF ))) +if (proto_is_dgram (c->c2.link_sockets[0 ]->info.proto) + && c->c2.fast_io && (flags & (IOW_TO_TUN |IOW_TO_LINK |IOW_MBUF ))) {/* fast path -- only for TUN/TAP/UDP writes */ unsigned int ret =0 ;
src/openvpn/init.c +19 -24
119 lines not on this page · raw message
src/openvpn/mtcp.c +0 -98
107 lines not on this page · raw message
src/openvpn/mtcp.h +0 -13
@@ -40,8 +40,6 @@void multi_tcp_instance_specific_free (struct multi_instance *mi); -void multi_tcp_set_global_rw_flags (struct multi_context *m,struct multi_instance *mi); -bool multi_tcp_process_outgoing_link (struct multi_context *m,bool defer,const unsigned int mpp_flags);bool multi_tcp_process_outgoing_link_ready (struct multi_context *m,struct multi_instance *mi,const unsigned int mpp_flags);
@@ -50,17 +48,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_io *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +8 -88
131 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m,struct link_socket *ls);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +94 -14
166 lines not on this page · raw message
src/openvpn/multi.h +2 -6
@@ -204,6 +204,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -251,11 +252,6 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() -* * @param top - Top-level context structure. */ void tunnel_server (struct context *top);
@@ -267,7 +263,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
src/openvpn/multi_io.c +48 -9
98 lines not on this page · raw message
src/openvpn/multi_io.h +2 -0
@@ -70,6 +70,8 @@void multi_io_process_io (struct multi_context *m); +void multi_io_set_global_rw_flags (struct multi_context *m,struct multi_instance *mi); +void multi_io_action (struct multi_context *m,struct multi_instance *mi,int action,bool poll);void multi_io_delete_event (struct multi_io *multi_io,event_t event);
src/openvpn/openvpn.h +2 -2
@@ -216,8 +216,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point() and \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +92 -12
195 lines not on this page · raw message
src/openvpn/options.h +5 -0
@@ -98,6 +98,7 @@ {const char *local;const char *port; +int proto; };struct connection_entry
@@ -917,6 +918,10 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); + +bool has_tcp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
src/openvpn/socket.c +23 -3
@@ -1888,11 +1888,31 @@struct options *o = &c->options;ASSERT (sock); +const char *host = o->ce.local_list->array[sock_index]->local; +const char *port = o->ce.local_list->array[sock_index]->port; +int proto = o->ce.local_list->array[sock_index]->proto;const char *remote_host = o->ce.remote;const char *remote_port = o->ce.remote_port; - sock->local_host = o->ce.local_list->array[sock_index]->local; - sock->local_port = o->ce.local_list->array[sock_index]->port; +if (c->mode ==CM_CHILD_TCP || c->mode ==CM_CHILD_UDP ) + { +struct link_socket *tmp_sock =NULL ; +if (c->mode ==CM_CHILD_TCP ) + { + tmp_sock = (struct link_socket *)c->c2.accept_from; + } +else if (c->mode ==CM_CHILD_UDP ) + { + tmp_sock = c->c2.link_sockets[0 ]; + } + + host = tmp_sock->local_host; + port = tmp_sock->local_port; + proto = tmp_sock->info.proto; + } + + sock->local_host = host; + sock->local_port = port; sock->remote_host = remote_host; sock->remote_port = remote_port; sock->dns_cache = c->c1.dns_cache;
@@ -1920,7 +1940,7 @@ sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; + sock->info.proto = proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; sock->info.lsa = &c->c1.link_socket_addrs[sock_index];
src/openvpn/ssl_common.h +0 -1
@@ -362,7 +362,6 @@int replay_window;/* --replay-window parm */ int replay_time;/* --replay-window parm */ -bool tcp_mode;const char *config_ciphername;const char *config_ncp_ciphers;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 20
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: cron2, ordex, plaisthos.
its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Patch Set 19:
(10 comments)
File doc/man-sections/link-options.rst:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/bb017af8_98251213 :
PS18, Line 122:
Quoted 1 line
I think we also should mention the default values, something like […]
Done, see options_postprocess_mutate_le(), now in a case like:
local * 1000 tcp
remote 1.2.3.4 1194 udp
Only the remote proto will be used
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/a19e31fc_278f6bab :
PS18, Line 335: const unsigned int status = m->multi_io->udp_flags;
Quoted 1 line
I do wonder why a separate
udp_flagsfield for UDP has been introduced. […]
As said in a comment above, the multi_io has no event_set_status member and since UDP require that I decided to call it udp_flags since it is UDP specific.
File src/openvpn/multi.h:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/9b01bf4b_df045866 :
PS19, Line 256: * on the transport protocols:
Quoted 1 line
The wording is a bit odd... […]
Done
File src/openvpn/multi_io.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/8d2cfb2d_b69e0502 :
PS19, Line 145: !proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto) ? &mi->tcp_rwflags : NULL);
Quoted 1 line
I like that this is being moved to a dedicated function :-) - I would style it differently, though, […]
TCP ev_arg are usually of type 'mi' while UDP are of type 'link_sockets'.
http://gerrit.openvpn.net/c/openvpn/+/764/comment/37cd169e_1703017b :
PS19, Line 491: }
Quoted 1 line
since this is the same
if (mi)now, it could go outside one level, avoid code duplication... […]
Done
File src/openvpn/openvpn.h:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/1ddc2f85_7dceb3e5 :
PS19, Line 219: * tunnel_point_to_point(), \c tunnel_server() \c
Quoted 1 line
an
andis missing beforetunnel_server()(since it's only these 2 functions now)
Done
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/1e2cfd64_b9b578a8 :
PS18, Line 3351: if (!le->proto)
Quoted 1 line
it says
acknowledgedbut we still have no comment forproto? ;-)
I've also added a check to avoid proto bindings on client side
http://gerrit.openvpn.net/c/openvpn/+/764/comment/8fe0a241_34255d82 :
PS18, Line 3839:
Quoted 1 line
so what does "Acknowledged" mean, here? "Will be handled in a future patch"?
Done
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/bc60012a_289c4f91 :
PS19, Line 1747: o->local_list->array[i]->port);
Quoted 1 line
I think this should show
protonow as well, otherwise the log is a bit hard to read if trying to u […]
Done
File src/openvpn/socket.c:
http://gerrit.openvpn.net/c/openvpn/+/764/comment/80bb9647_fc94b5d2 :
PS18, Line 1914: ASSERT(c->c2.link_sockets[sock_index]);
Quoted 1 line
maybe gerrit is playing tricks on me, but the
ASSERT()seems to be still here
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 19
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 05 Mar 2025 16:59:21 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: its_Giaan <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: cron2, ordex, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
to look at the new patch set (#21).
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Add support for simultaneous use of UDP and TCP sockets
Add all the bound sockets to the event loop. The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances. There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/multi_io.h
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c
M src/openvpn/ssl_common.h
17 files changed, 426 insertions(+), 325 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/21
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +121 -41
192 lines not on this page · raw message
src/openvpn/forward.h +7 -2
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
@@ -367,12 +371,13 @@/* * This is the core I/O wait function, used for all I/O waits except -* for TCP in server mode. +* for the top-level server sockets. */ static inline void io_wait (struct context *c,const unsigned int flags) { -if (c->c2.fast_io && (flags & (IOW_TO_TUN |IOW_TO_LINK |IOW_MBUF ))) +if (proto_is_dgram (c->c2.link_sockets[0 ]->info.proto) + && c->c2.fast_io && (flags & (IOW_TO_TUN |IOW_TO_LINK |IOW_MBUF ))) {/* fast path -- only for TUN/TAP/UDP writes */ unsigned int ret =0 ;
src/openvpn/init.c +19 -24
119 lines not on this page · raw message
src/openvpn/mtcp.c +0 -98
107 lines not on this page · raw message
src/openvpn/mtcp.h +0 -13
@@ -40,8 +40,6 @@void multi_tcp_instance_specific_free (struct multi_instance *mi); -void multi_tcp_set_global_rw_flags (struct multi_context *m,struct multi_instance *mi); -bool multi_tcp_process_outgoing_link (struct multi_context *m,bool defer,const unsigned int mpp_flags);bool multi_tcp_process_outgoing_link_ready (struct multi_context *m,struct multi_instance *mi,const unsigned int mpp_flags);
@@ -50,17 +48,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_io *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +8 -88
131 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m,struct link_socket *ls);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +94 -14
166 lines not on this page · raw message
src/openvpn/multi.h +2 -6
@@ -204,6 +204,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -251,11 +252,6 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() -* * @param top - Top-level context structure. */ void tunnel_server (struct context *top);
@@ -267,7 +263,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
src/openvpn/multi_io.c +48 -9
98 lines not on this page · raw message
src/openvpn/multi_io.h +2 -0
@@ -70,6 +70,8 @@void multi_io_process_io (struct multi_context *m); +void multi_io_set_global_rw_flags (struct multi_context *m,struct multi_instance *mi); +void multi_io_action (struct multi_context *m,struct multi_instance *mi,int action,bool poll);void multi_io_delete_event (struct multi_io *multi_io,event_t event);
src/openvpn/openvpn.h +2 -2
@@ -216,8 +216,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point() and \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +92 -12
195 lines not on this page · raw message
src/openvpn/options.h +5 -0
@@ -98,6 +98,7 @@ {const char *local;const char *port; +int proto; };struct connection_entry
@@ -917,6 +918,10 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); + +bool has_tcp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
src/openvpn/socket.c +23 -3
@@ -1888,11 +1888,31 @@struct options *o = &c->options;ASSERT (sock); +const char *host = o->ce.local_list->array[sock_index]->local; +const char *port = o->ce.local_list->array[sock_index]->port; +int proto = o->ce.local_list->array[sock_index]->proto;const char *remote_host = o->ce.remote;const char *remote_port = o->ce.remote_port; - sock->local_host = o->ce.local_list->array[sock_index]->local; - sock->local_port = o->ce.local_list->array[sock_index]->port; +if (c->mode ==CM_CHILD_TCP || c->mode ==CM_CHILD_UDP ) + { +struct link_socket *tmp_sock =NULL ; +if (c->mode ==CM_CHILD_TCP ) + { + tmp_sock = (struct link_socket *)c->c2.accept_from; + } +else if (c->mode ==CM_CHILD_UDP ) + { + tmp_sock = c->c2.link_sockets[0 ]; + } + + host = tmp_sock->local_host; + port = tmp_sock->local_port; + proto = tmp_sock->info.proto; + } + + sock->local_host = host; + sock->local_port = port; sock->remote_host = remote_host; sock->remote_port = remote_port; sock->dns_cache = c->c1.dns_cache;
@@ -1920,7 +1940,7 @@ sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; + sock->info.proto = proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; sock->info.lsa = &c->c1.link_socket_addrs[sock_index];
src/openvpn/ssl_common.h +0 -1
@@ -362,7 +362,6 @@int replay_window;/* --replay-window parm */ int replay_time;/* --replay-window parm */ -bool tcp_mode;const char *config_ciphername;const char *config_ncp_ciphers;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 21
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveAttention is currently required from: its_Giaan, ordex, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Patch Set 21: Code-Review+2
(1 comment)
Patchset:
PS21:
This looks really good now - with the latest changes, all my suggestions for comments or code have been included, and I can no longer crash it (survived a gremlin horde attack for 60+ minutes).
Undoubtedly there will be more things to fix, but let's move onwards!
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 21
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Thu, 06 Mar 2025 09:59:07 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH v21 1/1 Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archiveFrom: Gianmarco De Gregori <[email protected]...>
Add all the bound sockets to the event loop. The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances. There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/764
This mail reflects revision 21 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +121 -41
192 lines not on this page · raw message
src/openvpn/forward.h +7 -2
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
@@ -367,12 +371,13 @@/* * This is the core I/O wait function, used for all I/O waits except -* for TCP in server mode. +* for the top-level server sockets. */ static inline void io_wait (struct context *c,const unsigned int flags) { -if (c->c2.fast_io && (flags & (IOW_TO_TUN |IOW_TO_LINK |IOW_MBUF ))) +if (proto_is_dgram (c->c2.link_sockets[0 ]->info.proto) + && c->c2.fast_io && (flags & (IOW_TO_TUN |IOW_TO_LINK |IOW_MBUF ))) {/* fast path -- only for TUN/TAP/UDP writes */ unsigned int ret =0 ;
src/openvpn/init.c +19 -24
119 lines not on this page · raw message
src/openvpn/mtcp.c +0 -98
107 lines not on this page · raw message
src/openvpn/mtcp.h +0 -13
@@ -40,8 +40,6 @@void multi_tcp_instance_specific_free (struct multi_instance *mi); -void multi_tcp_set_global_rw_flags (struct multi_context *m,struct multi_instance *mi); -bool multi_tcp_process_outgoing_link (struct multi_context *m,bool defer,const unsigned int mpp_flags);bool multi_tcp_process_outgoing_link_ready (struct multi_context *m,struct multi_instance *mi,const unsigned int mpp_flags);
@@ -50,17 +48,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_io *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +8 -88
131 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m,struct link_socket *ls);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +94 -14
166 lines not on this page · raw message
src/openvpn/multi.h +2 -6
@@ -204,6 +204,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -251,11 +252,6 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() -* * @param top - Top-level context structure. */ void tunnel_server (struct context *top);
@@ -267,7 +263,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
src/openvpn/multi_io.c +48 -9
98 lines not on this page · raw message
src/openvpn/multi_io.h +2 -0
@@ -70,6 +70,8 @@void multi_io_process_io (struct multi_context *m); +void multi_io_set_global_rw_flags (struct multi_context *m,struct multi_instance *mi); +void multi_io_action (struct multi_context *m,struct multi_instance *mi,int action,bool poll);void multi_io_delete_event (struct multi_io *multi_io,event_t event);
src/openvpn/openvpn.h +2 -2
@@ -216,8 +216,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point() and \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +92 -12
195 lines not on this page · raw message
src/openvpn/options.h +5 -0
@@ -98,6 +98,7 @@ {const char *local;const char *port; +int proto; };struct connection_entry
@@ -917,6 +918,10 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); + +bool has_tcp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
src/openvpn/socket.c +23 -3
@@ -1888,11 +1888,31 @@struct options *o = &c->options;ASSERT (sock); +const char *host = o->ce.local_list->array[sock_index]->local; +const char *port = o->ce.local_list->array[sock_index]->port; +int proto = o->ce.local_list->array[sock_index]->proto;const char *remote_host = o->ce.remote;const char *remote_port = o->ce.remote_port; - sock->local_host = o->ce.local_list->array[sock_index]->local; - sock->local_port = o->ce.local_list->array[sock_index]->port; +if (c->mode ==CM_CHILD_TCP || c->mode ==CM_CHILD_UDP ) + { +struct link_socket *tmp_sock =NULL ; +if (c->mode ==CM_CHILD_TCP ) + { + tmp_sock = (struct link_socket *)c->c2.accept_from; + } +else if (c->mode ==CM_CHILD_UDP ) + { + tmp_sock = c->c2.link_sockets[0 ]; + } + + host = tmp_sock->local_host; + port = tmp_sock->local_port; + proto = tmp_sock->info.proto; + } + + sock->local_host = host; + sock->local_port = port; sock->remote_host = remote_host; sock->remote_port = remote_port; sock->dns_cache = c->c1.dns_cache;
@@ -1920,7 +1940,7 @@ sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; + sock->info.proto = proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; sock->info.lsa = &c->c1.link_socket_addrs[sock_index];
src/openvpn/ssl_common.h +0 -1
@@ -362,7 +362,6 @@int replay_window;/* --replay-window parm */ int replay_time;/* --replay-window parm */ -bool tcp_mode;const char *config_ciphername;const char *config_ncp_ciphers;
[Openvpn-devel] [PATCH applied] Re: Add support for simultaneous use of UDP and TCP sockets
This was really a tough one... we've wanted this for years, but digging deeply enough into the event handling for a p2mp server to make "TCP and UDP, at the same time" happen is a major achievement. A big thanks to Gianmarco and Antonio :-)
It also really needed "going up to v20" to become robust in the face of all the nasty things I tried - but now it just works. I ran this with 4 listening sockets, 2x UDP, 2x TCP, and 100 concurrent clients connecting and disconnecting randomly for 2 hours, and "it just works" (and of course it survives the normal server side testbeds just fine, but *that* was already achieved at v16 or so).
I have no doubts that there are some surprises still lurking, so having lots of real world exposure and testing will certainly be welcome...
Your patch has been applied to the master branch.
commit 619c3e9a067255f97e129bf02914f5ada5107b51
Author: Gianmarco De Gregori Date: Thu Mar 6 10:59:28 2025 +0100
Add support for simultaneous use of UDP and TCP sockets
Signed-off-by: Gianmarco De Gregori <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31028.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archivecron2 has uploaded a new patch set (#22) to the change originally created by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by cron2
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Add support for simultaneous use of UDP and TCP sockets
Add all the bound sockets to the event loop. The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances. There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31028.html
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/multi_io.h
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c
M src/openvpn/ssl_common.h
17 files changed, 426 insertions(+), 325 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/764/22
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +121 -41
192 lines not on this page · raw message
src/openvpn/forward.h +7 -2
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
@@ -367,12 +371,13 @@/* * This is the core I/O wait function, used for all I/O waits except -* for TCP in server mode. +* for the top-level server sockets. */ static inline void io_wait (struct context *c,const unsigned int flags) { -if (c->c2.fast_io && (flags & (IOW_TO_TUN |IOW_TO_LINK |IOW_MBUF ))) +if (proto_is_dgram (c->c2.link_sockets[0 ]->info.proto) + && c->c2.fast_io && (flags & (IOW_TO_TUN |IOW_TO_LINK |IOW_MBUF ))) {/* fast path -- only for TUN/TAP/UDP writes */ unsigned int ret =0 ;
src/openvpn/init.c +19 -24
119 lines not on this page · raw message
src/openvpn/mtcp.c +0 -98
107 lines not on this page · raw message
src/openvpn/mtcp.h +0 -13
@@ -40,8 +40,6 @@void multi_tcp_instance_specific_free (struct multi_instance *mi); -void multi_tcp_set_global_rw_flags (struct multi_context *m,struct multi_instance *mi); -bool multi_tcp_process_outgoing_link (struct multi_context *m,bool defer,const unsigned int mpp_flags);bool multi_tcp_process_outgoing_link_ready (struct multi_context *m,struct multi_instance *mi,const unsigned int mpp_flags);
@@ -50,17 +48,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_io *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +8 -88
131 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m,struct link_socket *ls);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +94 -14
166 lines not on this page · raw message
src/openvpn/multi.h +2 -6
@@ -204,6 +204,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -251,11 +252,6 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() -* * @param top - Top-level context structure. */ void tunnel_server (struct context *top);
@@ -267,7 +263,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
src/openvpn/multi_io.c +48 -9
98 lines not on this page · raw message
src/openvpn/multi_io.h +2 -0
@@ -70,6 +70,8 @@void multi_io_process_io (struct multi_context *m); +void multi_io_set_global_rw_flags (struct multi_context *m,struct multi_instance *mi); +void multi_io_action (struct multi_context *m,struct multi_instance *mi,int action,bool poll);void multi_io_delete_event (struct multi_io *multi_io,event_t event);
src/openvpn/openvpn.h +2 -2
@@ -216,8 +216,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point() and \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +92 -12
195 lines not on this page · raw message
src/openvpn/options.h +5 -0
@@ -98,6 +98,7 @@ {const char *local;const char *port; +int proto; };struct connection_entry
@@ -917,6 +918,10 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); + +bool has_tcp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
src/openvpn/socket.c +23 -3
@@ -1880,11 +1880,31 @@struct options *o = &c->options;ASSERT (sock); +const char *host = o->ce.local_list->array[sock_index]->local; +const char *port = o->ce.local_list->array[sock_index]->port; +int proto = o->ce.local_list->array[sock_index]->proto;const char *remote_host = o->ce.remote;const char *remote_port = o->ce.remote_port; - sock->local_host = o->ce.local_list->array[sock_index]->local; - sock->local_port = o->ce.local_list->array[sock_index]->port; +if (c->mode ==CM_CHILD_TCP || c->mode ==CM_CHILD_UDP ) + { +struct link_socket *tmp_sock =NULL ; +if (c->mode ==CM_CHILD_TCP ) + { + tmp_sock = (struct link_socket *)c->c2.accept_from; + } +else if (c->mode ==CM_CHILD_UDP ) + { + tmp_sock = c->c2.link_sockets[0 ]; + } + + host = tmp_sock->local_host; + port = tmp_sock->local_port; + proto = tmp_sock->info.proto; + } + + sock->local_host = host; + sock->local_port = port; sock->remote_host = remote_host; sock->remote_port = remote_port; sock->dns_cache = c->c1.dns_cache;
@@ -1912,7 +1932,7 @@ sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; + sock->info.proto = proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; sock->info.lsa = &c->c1.link_socket_addrs[sock_index];
src/openvpn/ssl_common.h +0 -1
@@ -362,7 +362,6 @@int replay_window;/* --replay-window parm */ int replay_time;/* --replay-window parm */ -bool tcp_mode;const char *config_ciphername;const char *config_ncp_ciphers;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 22
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: Add support for simultaneous use of UDP and TCP sockets
In reply to a message not in the archivecron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/764?usp=email )
Change subject: Add support for simultaneous use of UDP and TCP sockets
......................................................................
Add support for simultaneous use of UDP and TCP sockets
Add all the bound sockets to the event loop. The main server loop has been updated to handle both TCP and UDP connections.
The hash function has also been modified to include the protocol during the creation of new client instances. There are also a couple of refinements to make the whole code flow management capable of handling different kind of clients:
MULTI: properly remove TCP instances by checking the multi_instance
protocol instead of the global one.
TLS: set the tls_option xmit_hold bool value to true only in case of
TCP child instance to avoid checking the global protocol value.
INIT: initialize the c->c2.event_set in the inherit_context_top()
by default and not only in case of UDP since we could have multiple different sockets.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31028.html
---
M doc/man-sections/link-options.rst
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openvpn/multi_io.h
M src/openvpn/openvpn.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c
M src/openvpn/ssl_common.h
17 files changed, 426 insertions(+), 325 deletions(-)
doc/man-sections/link-options.rst +1 -1
@@ -106,7 +106,7 @@ is not reliable. It is recommended to set tun-mtu with enough headroom instead. ---local host|* [port] +--local host|* [port] [protocol] Local host name or IP address and port for bind. If specified, OpenVPN will bind to this address. If unspecified, OpenVPN will bind to all interfaces. '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
src/openvpn/forward.c +121 -41
192 lines not on this page · raw message
src/openvpn/forward.h +7 -2
@@ -69,6 +69,10 @@extern counter_type link_write_bytes_global; +void get_io_flags_dowork_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); + +void get_io_flags_udp (struct context *c,struct multi_io *multi_io,const unsigned int flags); +void io_wait_dowork (struct context *c,const unsigned int flags);void pre_select (struct context *c);
@@ -367,12 +371,13 @@/* * This is the core I/O wait function, used for all I/O waits except -* for TCP in server mode. +* for the top-level server sockets. */ static inline void io_wait (struct context *c,const unsigned int flags) { -if (c->c2.fast_io && (flags & (IOW_TO_TUN |IOW_TO_LINK |IOW_MBUF ))) +if (proto_is_dgram (c->c2.link_sockets[0 ]->info.proto) + && c->c2.fast_io && (flags & (IOW_TO_TUN |IOW_TO_LINK |IOW_MBUF ))) {/* fast path -- only for TUN/TAP/UDP writes */ unsigned int ret =0 ;
src/openvpn/init.c +19 -24
119 lines not on this page · raw message
src/openvpn/mtcp.c +0 -98
107 lines not on this page · raw message
src/openvpn/mtcp.h +0 -13
@@ -40,8 +40,6 @@void multi_tcp_instance_specific_free (struct multi_instance *mi); -void multi_tcp_set_global_rw_flags (struct multi_context *m,struct multi_instance *mi); -bool multi_tcp_process_outgoing_link (struct multi_context *m,bool defer,const unsigned int mpp_flags);bool multi_tcp_process_outgoing_link_ready (struct multi_context *m,struct multi_instance *mi,const unsigned int mpp_flags);
@@ -50,17 +48,6 @@void multi_tcp_link_out_deferred (struct multi_context *m,struct multi_instance *mi); - -/**************************************************************************/ -/** -* Main event loop for OpenVPN in TCP server mode. -* @ingroup eventloop -* -* @param top - Top-level context structure. -*/ -void tunnel_server_tcp (struct context *top); - -void multi_tcp_delete_event (struct multi_io *multi_io,event_t event);#endif /* ifndef MTCP_H */
src/openvpn/mudp.c +8 -88
131 lines not on this page · raw message
src/openvpn/mudp.h +2 -11
@@ -31,18 +31,9 @@struct context ;struct multi_context ; +unsigned int p2mp_iow_flags (const struct multi_context *m); -/** -* Main event loop for OpenVPN in UDP server mode. -* @ingroup eventloop -* -* This function implements OpenVPN's main event loop for UDP server mode. -* -* @param top - Top-level context structure. -*/ -void tunnel_server_udp (struct context *top); - - +void multi_process_io_udp (struct multi_context *m,struct link_socket *ls);/**************************************************************************/ /** * Get, and if necessary create, the multi_instance associated with a
src/openvpn/multi.c +94 -14
166 lines not on this page · raw message
src/openvpn/multi.h +2 -6
@@ -204,6 +204,7 @@struct buffer hmac_reply;struct link_socket_actual *hmac_reply_dest; +struct link_socket *hmac_reply_ls;/* * Timer object for stale route check
@@ -251,11 +252,6 @@* Main event loop for OpenVPN in server mode. * @ingroup eventloop * -* This function calls the appropriate main event loop function depending -* on the transport protocol used: -* - \c tunnel_server_udp() -* - \c tunnel_server_tcp() -* * @param top - Top-level context structure. */ void tunnel_server (struct context *top);
@@ -267,7 +263,7 @@* Called by mtcp.c, mudp.c, or other (to be written) protocol drivers */ -void multi_init (struct multi_context *m,struct context *t,bool tcp_mode); +void multi_init (struct multi_context *m,struct context *t);void multi_uninit (struct multi_context *m);
src/openvpn/multi_io.c +48 -9
98 lines not on this page · raw message
src/openvpn/multi_io.h +2 -0
@@ -70,6 +70,8 @@void multi_io_process_io (struct multi_context *m); +void multi_io_set_global_rw_flags (struct multi_context *m,struct multi_instance *mi); +void multi_io_action (struct multi_context *m,struct multi_instance *mi,int action,bool poll);void multi_io_delete_event (struct multi_io *multi_io,event_t event);
src/openvpn/openvpn.h +2 -2
@@ -216,8 +216,8 @@* \c SIGUSR1 restarts. * * This structure is initialized at the top of the \c -* tunnel_point_to_point(), \c tunnel_server_udp(), and \c -* tunnel_server_tcp() functions. In other words, it is reset for every +* tunnel_point_to_point() and \c tunnel_server() \c +* functions. In other words, it is reset for every * iteration of the \c main() function's inner \c SIGUSR1 loop. */ struct context_2
src/openvpn/options.c +92 -12
195 lines not on this page · raw message
src/openvpn/options.h +5 -0
@@ -98,6 +98,7 @@ {const char *local;const char *port; +int proto; };struct connection_entry
@@ -917,6 +918,10 @@bool key_is_external (const struct options *options); +bool has_udp_in_local_list (const struct options *options); + +bool has_tcp_in_local_list (const struct options *options); +/** * Returns whether the current configuration has dco enabled. */
src/openvpn/socket.c +23 -3
@@ -1880,11 +1880,31 @@struct options *o = &c->options;ASSERT (sock); +const char *host = o->ce.local_list->array[sock_index]->local; +const char *port = o->ce.local_list->array[sock_index]->port; +int proto = o->ce.local_list->array[sock_index]->proto;const char *remote_host = o->ce.remote;const char *remote_port = o->ce.remote_port; - sock->local_host = o->ce.local_list->array[sock_index]->local; - sock->local_port = o->ce.local_list->array[sock_index]->port; +if (c->mode ==CM_CHILD_TCP || c->mode ==CM_CHILD_UDP ) + { +struct link_socket *tmp_sock =NULL ; +if (c->mode ==CM_CHILD_TCP ) + { + tmp_sock = (struct link_socket *)c->c2.accept_from; + } +else if (c->mode ==CM_CHILD_UDP ) + { + tmp_sock = c->c2.link_sockets[0 ]; + } + + host = tmp_sock->local_host; + port = tmp_sock->local_port; + proto = tmp_sock->info.proto; + } + + sock->local_host = host; + sock->local_port = port; sock->remote_host = remote_host; sock->remote_port = remote_port; sock->dns_cache = c->c1.dns_cache;
@@ -1912,7 +1932,7 @@ sock->mark = o->mark; sock->bind_dev = o->bind_dev; - sock->info.proto = o->ce.proto; + sock->info.proto = proto; sock->info.af = o->ce.af; sock->info.remote_float = o->ce.remote_float; sock->info.lsa = &c->c1.link_socket_addrs[sock_index];
src/openvpn/ssl_common.h +0 -1
@@ -362,7 +362,6 @@int replay_window;/* --replay-window parm */ int replay_time;/* --replay-window parm */ -bool tcp_mode;const char *config_ciphername;const char *config_ncp_ciphers;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/764?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31bbf87e4e568021445c7512ecefadfd4a69b363
Gerrit-Change-Number: 764
Gerrit-PatchSet: 22
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-MessageType: merged